- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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.
Method 1
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.
Method 2
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