Search code examples
xcodeuinavigationbarbackground-color

Xcode Keep NavigationBar Color after Change View Color


I am using show segue to navigate to these two views. Profile view is a UIView, and Preferences view is a UITableView. The attributes for both of them are the same.

How can I make the navigation bar stay gray in the Profile view as in Preferences view?

To change the background color, I am using:

self.view.backgroundColor = UIColor.red

enter image description here

enter image description here


Solution

  • The navigationBar is translucent by default.
    You will need to explicitly disable that to ensure the navigationBar is a solid color in order to stop the background color from bleeding into it.

    self.navigationController?.navigationBar.isTranslucent = false