- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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
- How to create transparent Status Bar and Navigation Bar in iOS?
- How to get the Navigation Bar height in iOS?
- Adding Navigation Bar programmatically iOS using Swift
- How can I change the text color of the Navigation Bar on iOS?
- How to set background color of a View in iOS App?
- How to Set opacity for View in iOS?
- Set style to current link in a Navigation Bar with CSS
- How to create a navigation bar with equal-width navigation links with CSS?
- How to set random background for Recyclerview in Android?
- How to set subtitle for action bar in android?
- How to set title for action bar in android?
- How to create a dropdown navigation bar with CSS?
- How to permanently hide Navigation Bar in an Android Activity?
- Set Border for an ImageView in iOS?
- How to set default background color for JTextPane in Java?