Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove 1px border under UINavigationBar - not working

@IBOutlet var navBar: UINavigationBar!

self.navBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navBar.shadowImage = UIImage()

The code above works if the View Controller is embedded in a Navigation Controller and uses self.navigationController?.navigationBar.setBack... etc, but it doesn't work when using an IBOutlet (my example is not embedded in nav controller). The navigation bar is not translucent.

Any ideas?

like image 280
jskidd3 Avatar asked Dec 02 '14 16:12

jskidd3


2 Answers

Put this in you view controller (not in the uinavigationbar).

[[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[UIImage new]];
like image 73
Senõr Ganso Avatar answered Sep 30 '22 01:09

Senõr Ganso


Where exactly are you calling the appearance settings for a NavBar? When I try the following:

[self.myNC.navigationBar setShadowImage:[UIImage new]];
[self.myNC.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];

I have the desired effect.Could you provide us with a little more context perhaps?

like image 21
trdavidson Avatar answered Sep 30 '22 01:09

trdavidson