Created by Jamz Tang at 20 September 2011
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.
Clone this repository:
git clone git://gist.github.com/6913226.git UINavigationBar-JTDropShadow
If you think this is useful, share this article with your friends :)
blog comments powered by DisqusUINibDecoderProxy Observes what's encoded in an NSCoder object
JTKeyValueObserver Revisiting KVO+Block, the simplest version.
MethodSwizzle Method Swizzling in Objective-C
UITableViewDeleteActionResponder Quick hack to enable delete menu item in UITableView menuController
UIApplicationAddition Quickly switch supported UIInterfaceOrientation for your View Controllers
JTTargetActionBlock Adding Block support for UIControl's Target-Action mechanism
NSArray-JTArraySplit Splitting an array to several components
UIImage+JTImageDecode Force decompressing UIImage in background to achieve better performance
UINavigationBar-JTDropShadow Adding drop shadow on UINavigationBar (before iOS 6)
UIImage-JTImageCrop Crop an image in specific rect
UIView+JTRemoveAnimated Adding fadeout effect to any -[UIViews removeFromSuperview]
JTStringAddition NSStringf. Simpler printf styled +[NSString stringWithFormat:]
UIView-JTViewToImage Rendering any UIViews into UIImage in one line (updated with iOS 7 support)
NSObject-JTNibLoader Loading a Nib file programmatically using NSObject category
UIImage-JTColor Creating a placeholder UIImage dynamically with color
NSObject-JTCancelableScheduledBlock Cancelable Scheduled Blocks in Objective-C