Home > database >  Changing Color of the Navigation Bar's Safe Area Swift UIKit
Changing Color of the Navigation Bar's Safe Area Swift UIKit

Time:10-04

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

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

Let me know if you need any additional information.

CodePudding user response:

In my application I could not find a way to set the background color of the bar with SwiftUI so I used UIKit on initialization of my apps scene to set the color. Hope this helps

extension SceneDelegate {
    private func uiSetup() {
        // Navigation bar Appearance
        UINavigationBar.appearance().barTintColor = UIColor(red: 22, green: 22, blue: 22)
    }
}

CodePudding user response:

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

  • Related