Is there a way to delete the bottom border that iOS7 automatically displays under the navigationbar?
9 Answers
That does not work on iOS7 with navigation translucent or not...
A paste from Apple documentation;
Description The shadow image to be used for the navigation bar. The default value is nil, which corresponds to the default shadow image. When non-nil, this property represents a custom shadow image to show instead of the default. For a custom shadow image to be shown, a custom background image must also be set with the setBackgroundImage:forBarMetrics: method. If the default background image is used, then the default shadow image will be used regardless of the value of this property.
So basically you need to implement that setBackgroundImage. Additional note, on iOS7 you won't use appearance anymore but you'll modify the Navigation bar in the viewController context where you are now.
That is:
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
In my case I put this in viewDidLoad (custom behavior can be added for each UIViewController in the UINavigationViewController).

- 1,084
- 10
- 15
-
Thank you for the updated response and link to the documentation. – JVillella Jan 23 '15 at 03:20
-
2In my case, that's the answer that worked, not the first one. Thanks for the code and documentation. – Mauricio Vargas Apr 29 '15 at 18:41
-
1Using appearance still seems to work fine on 7+, but you will need to set both the `shadowImage` and `backgroundShadowImage` – bloudermilk Aug 18 '15 at 17:50
If i understand you correctly try
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];

- 2,285
- 1
- 19
- 23
-
33It's is probably worth noting that (as of iOS 7) in order for this to work you must also do [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault]. – Thomas Denney Sep 28 '13 at 09:20
-
4It isn't working for me on iOS 7. I've set the translucent property of the navbar to be false. Could that be an issue? – Bilbo Baggins Oct 17 '13 at 13:28
-
@BartSimpson Use both setShadowImage and setBackgroundImage. – Pétur Ingi Egilsson Aug 27 '14 at 14:12
based on muffed2k answer+ programming Thomas comment, this is what I'm using to show UINavigationBar without background image (ios5.1/6.0) and without bottom border(ios7.0) :
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6)
{
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
}else
{
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
}

- 2,259
- 2
- 34
- 55
If you're using Swift and you come across this question, try this in your main ViewController:
override func viewDidLoad() {
super.viewDidLoad()
/// ...
navigationController?.navigationBar.shadowImage = UIImage();
navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
//...
}
Based on @wolffan's answer above

- 3,516
- 1
- 22
- 28
For me follwing worked on iOS 7 to 9+ when translucent
is set to false
UINavigationBar.appearance().transluscent = false
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics:.Default)

- 31,918
- 20
- 95
- 134
I know there is an accepted answer to this already but another way to do it is setting clipToBounds to true.
Here is the one line of code to do it in swift
self.navigationController?.navigationBar.clipsToBounds = true
Worked for me like a charm.
-
1@user5209290 is correct. My status bar no longer blended with the navigation bar when clipping to the bounds of the navigation bar. – Daniel Zhang Sep 14 '15 at 21:58
Works like a charm: Swift 3.x version
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)

- 1,398
- 4
- 18
- 32
If you are targeting iOS 7 and are not setting a background image then this will work:
CGFloat navigationBarWidth = self.navigationController.navigationBar.frame.size.width;
CGFloat navigationBarHeight = self.navigationController.navigationBar.frame.size.height;
CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(navigationBarWidth, navigationBarHeight + statusBarHeight), NO, 0.0);
UIImage *blank = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[UINavigationBar appearance] setBackgroundImage:blank forBarMetrics:UIBarMetricsDefault];
//the following line takes away the border but only works if a background image is set (above)
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
I got the idea from @muffe2k's answer and this SO post.

- 1
- 1

- 5,144
- 6
- 43
- 65