Changing navigation bar color in Swift
Navigation Bar:
navigationController?.navigationBar.barTintColor = UIColor.green
Replace greenColor with whatever UIColor you want, you can use an RGB too if you prefer.
Navigation Bar Text:
navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.orange]
Replace orangeColor with whatever color you like.
Tab Bar:
tabBarController?.tabBar.barTintColor = UIColor.brown
Tab Bar Text:
tabBarController?.tabBar.tintColor = UIColor.yellow
On the last two, replace brownColor and yellowColor with the color of your choice.
iOS 7 Navigation Bar text and arrow color
Behavior from some of the properties of UINavigationBar
has changed from iOS 7. You can see in the image shown below :
Two beautiful links I'd like to share with you. For more details you can go through these links :
- iOS 7 UI Transition Guide.
- How to Update Your App for iOS 7.
Apple Documentation for barTintColor says :
This color is made translucent by default unless you set the
translucent property to NO.
Sample Code :
self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar
setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
self.navigationController.navigationBar.translucent = NO;
Change navigation bar tint color iOS 7.
you can add bellow code in appdelegate.m
if your app is navigation based
// for background color
[nav.navigationBar setBarTintColor:[UIColor blueColor]];
// for change navigation title and button color
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"FontNAme" size:20], NSFontAttributeName, nil]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
How do I change the colour of the status bar when the navigation bar is hidden in iOS 7?
Add a UIView
under the status bar and set its backgroundColor
property to the navigation bars barTintColor
Navigation Bar color doesn't change back? iOS7
Put that in viewWillAppear:
. Code in this method will be run every time the view reappear.
Unable to change navigation bar color
There are two ways to do this. You can either modify the appearance proxy that you have set up in the AppDelegate for the whole app, or you can modify the individual navigationbar for the particular screen.
When you dismiss the view - you need to reset the barTintColor in the viewWillDisappear.
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// Set to new colour for whole app
UINavigationBar.appearance().barTintColor = UIColor.blueColor()
// Or, Set to new colour for just this navigation bar
self.navigationController?.navigationBar.barTintColor = UIColor.blueColor()
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
//Revert to old colour, whole app
UINavigationBar.appearance().barTintColor = UIColor.redColor()
//Revert to old colour, just this navigation bar
self.navigationController?.navigationBar.barTintColor = UIColor.redColor()
}
Related Topics
How to Run Cocoapods on Apple Silicon (M1)
Assertion Failure in Dequeuereusablecellwithidentifier:Forindexpath:
Why Is There Extra Padding At the Top of My Uitableview With Style Uitableviewstylegrouped in Ios7
How to Easily Resize/Optimize an Image Size With Ios
How to Use Background Thread in Swift
How to Record Audio on Iphone With Avaudiorecorder
How to Install iOS 6 Sdk on Xcode 5
How to Force View Controller Orientation in iOS 8
Firebase Query - Find Item With Child That Contains String
How to Check When a Uitextfield Changes
Setting Action For Back Button in Navigation Controller
Objective-C and Swift Url Encoding
How to Add Uitableview Within a Uitableviewcell
Get to Uiviewcontroller from Uiview
Remove Alpha Channel in an Image
Xcode Error "Could Not Find Developer Disk Image"
How to Load an Http Url With App Transport Security Enabled in iOS 9