- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set background for Navigation Bar in iOS?
To set the background color for a navigation bar we can either do it programmatically or through the storyboard if it is on storyboard.
Let's see how to change the background color of a navigation bar through the storyboard editor.
Create a new project, select it's view controller and embed in navigation controller.
Select the navigation bar and go to It's attribute inspector.
This is how it looks in the Xcode 10. You can select the tint color from there and it will be changed for the navigation controller.
Programmatically changing the navigation background.
To programmatically change it, go to the view controller and inside, ViewDidLoad or ViewWillAppear write the following code:
self.navigationController?.navigationBar.barTintColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
to change other properties like text color, tint color or transparency you can use
UINavigationBar.appearance().barTintColor = .black UINavigationBar.appearance().tintColor = .white UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white] UINavigationBar.appearance().isTranslucent = false
Kickstart Your Career
Get certified by completing the courseGet Started