Created by Jamz Tang at 20 September 2011

Adding drop shadow on UINavigationBar (before iOS 6)

We've an update on this technique for iOS 6.1, please see

Using custom drop shadows in UINavigationBar (fix for iOS 6.1)


Somehow adding drop shadows on UINavigationBar using the CALayer property fails for me but I later find it out we just need a little trick there.

// The magic is to have -[UIView clipToBounds] set to NO
self.navigationController.navigationBar.clipsToBounds = NO;

Base on the fact this is ioscodesnippet, I know I have to make a really simple UINavigationBar-JTDropShadow category to make our life more easier.

Usage:

- (void)viewDidLoad {
    [super viewDidLoad];
    ...
    [self.navigationController.navigationBar dropShadowWithOffset:CGSizeMake(0, 3)
                                                           radius:1
                                                            color:[UIColor darkGrayColor]
                                                          opacity:1];
    ...
}

Make sure you've already imported QuartzCore.framework in your build settings.

While it is more generic by making it a UIView category, but I’ll leave it simple here to demonstrate the main purpose.


Installation

Clone this repository:
git clone git://gist.github.com/6913226.git UINavigationBar-JTDropShadow

Download | More...


If you think this is useful, share this article with your friends :)

blog comments powered by Disqus

ioscodesnippet.com