Reputation: 5053
I am using NavigationBar in swift5. NavigationBar background color shows black color.. here is my image
Here is my code:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.tintColor = UIColor.red
self.navigationController?.navigationBar.barTintColor = UIColor.green
self.navigationController?.navigationBar.barTintColor = .red
self.navigationItem.title = "ABC title"
self.navigationController!.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]
self.navigationController?.navigationBar.isTranslucent = false
}
}
What is the problem of my code? Please help me
Upvotes: 2
Views: 137
Reputation: 498
You can simply change the navigation bar background Colour using this Code
self.navigationController?.navigationBar.backgroundColor = UIColor.green
Upvotes: 1
Reputation: 337
This is why in iOS 15 NavigationBars use the scrollEdgeAppearance, if you want to use old appearance you have to declare it like this :
override func viewDidLoad() {
super.viewDidLoad()
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .red
appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]
self.navigationController?.navigationBar.standardAppearance = appearance;
self.navigationController?.navigationBar.scrollEdgeAppearance = self.navigationController?.navigationBar.standardAppearance
self.navigationItem.title = "ABC title"
}
That's the result :
Upvotes: 3