Reputation: 385
I have a segue connecting two views. In the parent view, the navigation bar is a gray color, and in the child view, it's clear. When unwinding the segue, the navigation bar in the parent controller is now clear as well. How to fix this?
Parent Controller
override func viewWillAppear(animated: Bool) {
self.navigationItem.title = "FEED"
self.navigationController?.navigationBar.barTintColor = UIColor(white:0.97, alpha:1.0)
let navBarLineView = UIView(frame: CGRectMake(0,
CGRectGetHeight((navigationController?.navigationBar.frame)!),
CGRectGetWidth((self.navigationController?.navigationBar.frame)!),
1))
navBarLineView.backgroundColor = UIColor(red:0.91, green:0.91, blue:0.92, alpha:1.0)
navigationController?.navigationBar.addSubview(navBarLineView)
}
Child Controller
override func viewWillAppear(animated: Bool) {
self.navigationItem.title = "Space
self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()
navigationController!.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
navigationController!.navigationBar.shadowImage = UIImage()
navigationController!.navigationBar.translucent = true
}
Upvotes: 1
Views: 183
Reputation: 11881
Setting background and shadow images to nil
in viewWillDisappear
method in the child controller worked fine for me when I wanted to restore default style of navigation bar:
override func viewWillDisappear(animated: Bool) {
navigationController!.navigationBar.setBackgroundImage(nil, forBarMetrics: UIBarMetrics.Default)
navigationController!.navigationBar.shadowImage = nil
}
Upvotes: 0