Gugulethu Gugulethu - 1 year ago 83
iOS Question

Re-Showing the Hairline

I have a two

with Embedded Navigation Controllers.
shows the hairline/shadow under the nav bar and
doesn't show it when I navigate to it. Navigation is done using the Push Segue

To hide the navigation bar in
I adding the following lines in
the following:

self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = false

When I use the back button to go back to ViewController-1 the Hairline disappears there too but I do not want it to. Is there anyway to ensure that the hairline doesn't hide in

I have tried :

self.navigationController?.navigationBar.barStyle = UIBarStyle.Black


self.navigationController?.navigationBar.backgroundColor = UIColor.whiteColor()

but without much success.

Answer Source

In the viewWillDisappear (or maybe the viewDidDisappear) method of ViewController-2, add code to undo the changes made in viewWillAppear.

self.navigationController?.navigationBar.setBackgroundImage(nil, forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = nil
self.navigationController?.navigationBar.translucent = true