It seems in iOS 6, a drop shadow is automatically added to the navigation bar even when you set a custom background image. I\'m pretty sure this wasn\'t the case with iOS 5
Since self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
not working, I've found an easy and workable way to remove the shadow of UINavigationBar
in both iOS 6 AND iOS 5. Hope people who need can see this post.
All you have to do is prepare one background image that the height is 1 pixel larger than your navigation bar height (e.g. 320×45 for default UINavigationBar, 640×90 for 2x of course).
Then just use [[UINavigationBar appearance] setBackgroundImage: ...]
, you will find shadow is replaced by that 1 pixel. cheers!
BTW I found Twitter has done the exactly same thing, if you unzip Twitter.ipa
and look into bg_nav_bar_events_dark.png
, the size is 320×47. They made their own shadow for 3 pixels :)
General, non-NDA-infringing answer:
If you don't want something sticking out of a layer, mask the layer to its bounds.
[self.layer setMasksToBounds:YES];
Set the height explicitly to 44 (or 32 for landscape on iPhone) if that doesn't work on its own.
I had the same problem and I've solved it by following:
CustomNavBar *navBar = (CustomNavBar *)self.navigationController.navigationBar;
[navBar setBackgroundImage:[UIImage imageNamed:@"navigation_bar_gray.png"] forBarMetrics:UIBarMetricsDefault];
navBar.shadowImage = [[UIImage alloc]init]; // this is what acctually removed the shadow under navigation bar
Also you can try this:
controller.navigationBar.shadowImage = [[[UIImage alloc] init] autorelease];
controller is a UINavigationController.
How about the alternative way:
UINavigationBar.appearance().barStyle = .Black
For the dark navigation bars iOS doesn't show the shadow.
I know this has been solved with more complicated answers above, but this is the quickest and easiest way I hid the shadow under the navigation bar.
self.navigationController.navigationBar.clipsToBounds = YES;