Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove UINavigationBar inner shadow in iOS 7?

Inner shadow example

I'm trying to put nav bar below the other one to make it look like one tall nav bar. But in iOS 7 UINavigationBar now has inner shadow on top and on bottom of it. I really need to remove it. But I didn't found any solution. It looks like the shadow is prerendered, but in fact it slowly appears in about 0.4 second after the view appears.

I've tried almost everything but the shadow is still there. I removed the horizontal line below the bar with this code:

for (UIView *view in [[[self.navigationController.navigationBar subviews] objectAtIndex:0] subviews]) {
     if ([view isKindOfClass:[UIImageView class]]) view.hidden = YES;
}

But I can't figure it out how to remove the shadow. Thanks a lot!

I've tried this:

[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];

But that code doesn't even remove the horizontal line below the bar (this method needs custom background image). I use Xcode Version 5.0 (5A11365x)

like image 563
TOVVV Avatar asked Aug 10 '13 08:08

TOVVV


2 Answers

The "horizontal" line at the bottom of the navigation bar is simply it's shadowImage. It can simply be removed by applying an empty UIImage. According to the documentation you also have to set a custom background image:

- (void)viewDidLoad {     [super viewDidLoad];      // Set the background and shadow image to get rid of the line.     [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];     self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init]; } 
like image 80
Thyraz Avatar answered Nov 01 '22 14:11

Thyraz


I really shouldn't as CaptJak has pointed out but for anyone else who gets stuck:

for (UIView *view in self.navigationController.navigationBar.subviews) {
    for (UIView *view2 in view.subviews) {
        if ([view2 isKindOfClass:[UIImageView class]]) {
            [view2 removeFromSuperview];
        }
    }
}

enter image description here

like image 21
Rambatino Avatar answered Nov 01 '22 14:11

Rambatino