change navigationbar button colors for ios7 - ios

I am trying to find out how to change the text and arrow color of the UINavigationBar buttons.
I know how to change the titleTextAttributes but cannot find out how to do it to the buttons.
For example this is how I change the titleTextAttributes inside my AppDelegate
self.navigationController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName : [UIColor redColor]};
I have looked through the UINavigationBar docs and cannot find any button attributes so not sure what to do here.

to change the text color and the color of the arrow in the navigation bar you can use this code (iOS 7):
self.navigationController.navigationBar.tintColor = [UIColor redColor];
this code will also change the color of the buttons

You can globally change it as easy as this

Related

TintColor Changing on Popover Push

I'm setting the tint color of a window to an arbitrary color, then trying to over-ride this on a per-button basis, but it appears that the buttons revert to the window tint color whenever there is a segue applied on them.
Setting tint color in didFinishLaunchingWithOptions:
self.window.tintColor = [UIColor redColor];
and then my two buttons in viewDidLoad:
[self.button1 setImage:[[UIImage imageNamed:#"711-trash"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
self.button1.tintColor = [UIColor purpleColor];
self.button2.tintColor = [UIColor blueColor];
where button1 is a custom type button and button2 is a system type button.
When the popover first presents, the two buttons are tinted purple and blue. But when the segue view controller is pushed, the popped, the two buttons switch to red. Is there any way to prevent this?
EDIT:
I've tried reproducing your code like this:
However everything worked as expected:
So I agree with #user3779315, possibly you are setting the buttons' tint color somewhere else. Btw, additional code of your project would help to clarify the issue :-)

Can you change the color of the UINavigationBar and status bar separately?

I have a view that I'm trying to 'dim'. I'm creating a UIView with a black background color and alpha of 0.4. I lay this view over my view, and I also change the color of my of navigationbar by change the RGB values (the correct way to get this is to take the RGB value and multiply it by 1.0-0.4 to get 0.6. Anyway, that's beside point).
I want to 'dim' my main view, and 'dim' the UINavigationBar... but I don't want the status bar to be 'dimmed'.
However, I can't figure out how to do this. When I change [self.navigationcontroller.navigationbar setBarTintColor:
Is there a way to set the colors individually?
Yes you're on the right track, You can set the color of the bar by using these methods, the barTintColor
//Navigation Bar
[self.navigationController.navigationBar setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]}];
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:53.0/255.0 green:53.0/255.0 blue:53.0/255.0 alpha:1.0];

Changing the colour of Navigation Controller bottom toolBar

I am trying to change the colour of the bottom bar of my Navigation Controller. I have managed to change the top NavBar in my appdelegate by adding
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.688 green:0.437 blue:0.794 alpha:1.0]];
I want to apply this to the bottom bar also.
You can use [UIToolbar appearance] to set the appearance of UIToolbar
Good luck
I had the same problem, but could escape this by setting a tag for my navigationBar in my storyboard. Then I could change the navigationBar's color like this:
let navigationBar = (self.view.viewWithTag(someNumber) as UINavigationBar)
navigationBar.barTintColor = UIColor.blackColor()
This is not ideal unless you can guarantee that the number of subviews in your view is less than "someNumber". If you can though, then this should work.

Using global Tint color as UINavigationBars backgroundColor

i need to set the UINavigationBars background color to the same value as my apps global tint color.
problem here is that now all buttons in my navigation bar are the same color as its background. i now could change all UIBarButtons text color to white but this would be totally unusable. using the UIAppearance API doesn't seem to be a better way. after setting the text color of UIBarButton items to white, f.e the back arrows of the back button in my UINavigationBar are still painted with the global tint color.
also if i change the global tint color to white i loose all the flexibility that the global tint color gives us (also my text indicator would now be white and would not be seen on a white background)
what i want:
what i get using blue as global tint color
what i get when using blue as global tint color and setting uibarbutton items text color to white (see the back button - it should be white as well)
what is the recommended way to fix this problem?
I recommend that you do this:
UINavigationBar *navigationBar = [UINavigationBar appearance];
navigationBar.tintColor = [UIColor whiteColor];
Place this code in the didFinishLaunchingWithOptions: method in the AppDelegate.
For clarification as you are obviously not very experienced with this:
barTintColor is the property that would change the bar colour. tintColor changes the colour of interactive objects (such as the UIBarButtonItems)
if ([[UINavigationBar class] respondsToSelector:#selector(appearance)]) {
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
}
Try to set UINavigationBar setTintColor in specified controller (in viewDidLoad for example).

customize UIBarButtonItem in Navigation Bar

I was trying to customizing the UIBarButtonItem in Navigation Bar
I found that there is a property in UIBarButtonItem : "tintColor" , and I set it like this
self.navigationItem.leftBarButtonItem.tintColor = [UIColor redColor];
It works well, but if I try this :
self.navigationItem.leftBarButtonItem.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"imageName"]];
1. It doesn't work as expect , however , the leftBarButtonItem shows a black appearance ,why ?
If I try a clearColor :
self.navigationItem.leftBarButtonItem.tintColor = [UIColor clearColor];
2. The leftBarButtonItem shows a black appearance still, why ?
3. I want to customize it with a pattern image like above , how can I do that ?
Thank you
You can check this sample code for customizing navigation bar and back button
https://github.com/boctor/idev-recipes/tree/master/CustomBackButton

Resources