Reputation: 633
Is there a way to delete the bottom border that iOS7 automatically displays under the navigationbar?
Upvotes: 37
Views: 23502
Reputation: 1398
Works like a charm: Swift 3.x version
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
Upvotes: 1
Reputation: 11
for objective c
self.navigationController.navigationBar.clipsToBounds = YES;
Upvotes: 1
Reputation: 55699
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)
Upvotes: 4
Reputation:
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.
Upvotes: 2
Reputation: 3636
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
Upvotes: 6
Reputation: 5246
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.
Upvotes: 0
Reputation: 1104
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).
Upvotes: 48
Reputation: 2287
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];
}
Upvotes: 12
Reputation: 2295
If i understand you correctly try
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
Upvotes: 46