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
}
}
If you are looking for a simple way to change the color of a View’s Navigation Bar, the code snippet below may be helpful. This works on any top level layout container like a NavigationStack, VStack, List, etc. The basic approach is to replace the navigation Title with an empty String, set the navigationBarBackButtonHidden to ‘true’ and build your own Navigation Bar. Here is the code. Explanations are inline.
//
// MyApplicationView.swift
// Customize Navigation Title & Back Button
//
// Created by Mike Montgomery on 6/6/25.
//
import SwiftUI
struct MyApplicationView: View {
//Create a property to read the 'isPresented' EnvironmentValue inside a view to know when SwiftUI presents that view.
@Environment(\.isPresented) private var isPresented
//Create a property to access the EnvironmentValue action that dismisses the current presentation.
@Environment(\.dismiss) private var dismiss
var body: some View {
NavigationStack {
//...Some destination View...
}
//set the navigation title to an empty string so it does not display
.navigationTitle("")
//hide the navigation bar back button
.navigationBarBackButtonHidden(true)
//Build a new navigation bar with a horizontal layout
.toolbar(content:{
ToolbarItem(placement: .navigation) {
HStack{
//Use a SF Symbol for a Back button
Image(systemName: "arrowshape.left.fill")
.foregroundColor(.red)
.onTapGesture() {
//Enable button functionality using these EnvironmentValue properties
if isPresented{
dismiss()
}
}
//Use a Text View to display a new custom navigation title in the color of your choice
Text("My Custom Navigation Title")
.bold()
.foregroundColor(.red)
.font(.custom("Avenir", size:12))
}
}
})
}
}
#Preview {
MyApplicationView()
}