I’ve just got a problem while changing the colour of navigation bar to custom colour and the problem is that the colour is not getting changed whether I do it programmatically or from Interface(StoryBoard)
I’ve searched for this problem on google , only one solution I found for this , I applied this solution but, no results.
App runs fine but with no change in colour , however at console following error shows up: [Assert] UINavigationBar decoded as unlocked for UINavigationController, or navigationBar delegate set up incorrectly. Inconsistent configuration may cause problems. navigationController=<UINavigationController: 0x116815200>, navigationBar=<UINavigationBar: 0x115d07d00; frame = (0 0; 0 50); opaque = NO; autoresize = W; tintColor = UIExtendedGrayColorSpace 1 1; layer = <CALayer: 0x283fcfe40>> delegate=0x116815200
Hi Huzaifa, did you get a solve? I have the same error, all I did was embed Nav Controller. Looked around, and from what I read on Reddit, StackO and Apple threads, seems it’s an Apple bug. Hope they address it.
I can see what you wanted to achieve here. Changing the navigation bar’s translucency or barTintColor directly no longer works ever since iOS 15.
The iOS 13 SDK introduced an appearance settings class for the UINavigationBar called UINavigationBarAppearance.
In iOS 15, by default the appearance settings applied produces a transparent background to all navigation bar styles. You can read more about it from Apple’s technical notes for the UINavigationBar.
If you’re targeting a minimum target of iOS 15 and later, you can try using:
override func viewDidLoad() {
super.viewDidLoad()
let newNavBarAppearance = UINavigationBarAppearance()
// Configuring an opaque background
newNavBarAppearance.configureWithOpaqueBackground()
// or you can use:
// newNavBarAppearance.configureWithTransparentBackground()
// when you wanted a configuration with a transparent background
// Navigation bar's background color
newNavBarAppearance.backgroundColor = .purple
// Navigation bar's title foreground color
newNavBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
// Apply the appearance to different styles:
navigationController?.navigationBar.scrollEdgeAppearance = newNavBarAppearance
navigationController?.navigationBar.compactAppearance = newNavBarAppearance
navigationController?.navigationBar.standardAppearance = newNavBarAppearance
if #available(iOS 15.0, *) {
navigationController?.navigationBar.compactScrollEdgeAppearance = newNavBarAppearance
}
}