How to change UINavigationBar Title and Back Button Colour from Storyboard? - ios

What is the best way of changing colors for Title and Back button of UINavigationBar from Storyboard?

What is the best way of changing colors for Title and Back button of UINavigationBar from Storyboard?
The color of the title is an attribute of the navigation bar, so select the navigation controller's navigation bar:
and then look at the Attributes Inspector, where you can set the title color:
The color of the Back button is controlled by the tint color. You can set the global tint color in the File Inspector for the storyboard:
These settings should work fine if you want to set the title and tint color once for the whole app, but if you want different colors for different view controllers, then one way or another you're going to have to write some code. If that's something you need to do often, and you want to be able to set the colors in IB, you could consider writing your own UIViewController subclass from which all your view controllers are derived. Give that common controller class inspectable attributes for the colors you want to set, and of course add code that sets them appropriately. You'll probably want to use UIAppearance for that.
Bear in mind, though, that the reason that these colors aren't already attributes of UIViewController is that the colors are supposed to help give your app a consistent appearance; changing your app's color scheme from one scene won't be a favor to your users.

you can do it by code
navigationController?.navigationBar.backgroundColor = UIColor.red
navigationController?.navigationBar.isTranslucent = false
let button1 = UIBarButtonItem(image: UIImage(named: "search.png"), style: .plain, target: self, action: #selector(barBut)) // action:#selector(Class.MethodName) for swift 3
self.navigationItem.rightBarButtonItem = button1
navigationController?.navigationBar.tintColor = .white

Related

Xcode transparent navigation bar background

I'm using a custom navigation bar in a view, and I want the bar not to be visible (except for the text and the buttons of course). the view is white, therefore the background of the bar needs to be also white or transparent. but no matter, what I try, it is always barely visible:
This is what it looks like(I know you have to look hard, but the bottom line is visible):
if I need to write any code, please use swift
Try this :
self.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationBar.shadowImage = UIImage()
self.navigationBar.isTranslucent = true

UINavigationController Title Not Using Correct Tint

I've adjusted the default tint of my navigation bar to be white and it appropriately adjusts the color of each of my navigation bar elements:
However, when I push to a new view controller and try to set the title property, the tint is no longer applied:
I know that I can supply a label or something similar to the titleView attribute of my view controller that would do the trick, but that's a lot of work (relatively speaking) and in my mind the text should just default to the navigation bar's tint color. Am I missing something else? Or is this standard behavior that requires a custom titleView to override?
The tint property does not affect the color of the title. To set the title color (along with other attributes like font) globally, you can set the titleTextAttributes property of the UINavigationBar appearance to suit your needs. Just place this code in your AppDelegate or somewhere else appropriate that gets called on launch:
Swift 3:
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
Swift 2
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
No you work correctly. But you should to set color for second view. You can use this code to solve your problem.
In second view write this code to set color and font for your navigation title.
navigationController!.navigationBar.titleTextAttributes = ([NSFontAttributeName: UIFont(name: "Helvetica", size: 25)!,NSForegroundColorAttributeName: UIColor.white])

Is there a way to change the back button color when using the navigation controller in Xcode [duplicate]

I'm having problems trying to figure out how to change the color of the buttons on the navigation controller.
Previously I had used the following:
[[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:226/255.0 green:66/255.0 blue:66/255.0 alpha:0.0]];
and this worked, but I added a new view with a toolbar, and the tool bar button images will not show. If I remove the global coloring, the tool bar items show just fine.
I've tried setting the tint color on both the leftBarButtonItem and the backBarButtonItem in the viewDidLoad method of the view, but both of those properties appear to be null.
I don't want to change the color of the entire navigation bar, just the buttons. Is there a way to do this?
Yeah, I'll just post this as an answer. Your alpha is set to 0. So you're basically saying the same thing as [UIColor clearColor].
Not sure how that ever worked to give you a tint color on your bar button items.
In swift, it can be accomplished by the following command:
if let navController = self.navigationController
{
navController.navigationBar.tintColor = UIColor.whiteColor()
}

Is it possible to change navigation bar color when I press a uibutton?

I'm wondering if its possible to change the color of Ui Navigation Bar color in Swift 2? Imagine whatsapp white color is changable to any color as the user press a button in settings for example. I have Googled for this online but didn't find anything.
Thanks.
In your buttons action just add
// UINavigationItem buttons
self.navigationController?.navigationBar.tintColor = UIColor.blueColor()
// NavigationBar color
self.navigationController?.navigationBar.barTintColor = UIColor.greenColor()
You can use the UINavigationBar's property barTintColor.
Documentation: UINavigationBar Class Reference

Change to color of back button

When I configured a segue from a table view cell to another VC which embedded in a nav Controller, there was a little back button(blue color) in the nav bar, i did not add any bar buttons in my story boards, but i want its color to be white. I have tried the following code:(in my viewDidLoad() method)
UIBarButtonItem.appearance().tintColor = UIColor.whiteColor()
and this:
self.navigationController.navigationBar.tintColor = UIColor.whiteColor()
or any other similar codes...they were all not working.
Can anyone help me out?
If you set the global tint color in the storyboard, it will affect the color of the back button.

Resources