skip to Main Content

I am running into an issue. I want the whole navigation bar (including safe area) color to change but the safe area color doesnt change at all (no matter what changes I make to it).

Heres

navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.backgroundColor = .green
    
navigationItem.titleView = searchBar

I even tried changing the Nav Bar’s:

  • barTintColor
  • tintColor

with no luck.

Current Navigation Bar Color

enter image description here

This view controller is being presented from the Scene Delegate using a navigation controller.

Let me know if you need any additional information.

2

Answers


  1. Chosen as BEST ANSWER

    Found a solution:

    
    let appearance = UINavigationBarAppearance()
    appearance.configureWithOpaqueBackground()
    appearance.backgroundColor = .green
    navigationController?.navigationBar.standardAppearance = appearance
    navigationController?.navigationBar.scrollEdgeAppearance = navigationController?.navigationBar.standardAppearance
                
    navigationItem.titleView = searchBar
    

    I entered this in the function where I was configuring the navigation bar

    Credit: https://developer.apple.com/forums/thread/682420


  2. Try this in your SceneDelegate

    if #available(iOS 15, *) {
            let navigationBarAppearance = UINavigationBarAppearance()
            navigationBarAppearance.configureWithOpaqueBackground()
            navigationBarAppearance.titleTextAttributes = [
                NSAttributedString.Key.foregroundColor : UIColor.white
            ]
           
            navigationBarAppearance.shadowColor = nil
            navigationBarAppearance.backgroundColor = .green
            UINavigationBar.appearance().barStyle = .green
            UINavigationBar.appearance().standardAppearance = navigationBarAppearance
            UINavigationBar.appearance().compactAppearance = navigationBarAppearance
            UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance
            
            
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search