i'm porting now ios6 app to ios7 sdk (with Xcode 5 and mavericks) and i tried to change UIBarButtonItem color, here is what i try to do:
self.navigationController.navigationBar.tintColor
- make changes color for bar but not for items
[[UINavigationBar appearance] setTintColor:[UIColor greenColor]];
[[UIBarButtonItem appearance] setTintColor:[UIColor greenColor]];
- doesn't work, same wrong color
self.navigationItem.rightBarButtonItem.tintColor = [UIColor greenColor];
self.navigationItem.leftBarButtonItem.tintColor = [UIColor greenColor];
- doesn't work, same wrong color
UIBarButtonItem *close = [[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString(@"Close",@"")
style:UIBarButtonItemStyleDone target:self
action:@selector(closeAddressBook:)];
close.tintColor = [UIColor greenColor];
- doesn't work, same wrong color
for self.filterSegment.tintColor = [UIColor greenColor] where UISegmentedControl *filterSegment;
i see unselected segment with correct color, but selected segment is a same wrong color.
any ideas?
Figured out what needs to be done, thanks to WWDC 2013 - Customizing Your App’s Appearance for iOS 7.
self.navigationController.navigationBar.tintColor = [UIColor redColor];
This will filter down into the other views in your app, so place on initial screen, and if you push to the next screen you will see that the back button is also red.
To change the navigation bar colour use
self.navigationController.navigationBar.barTintColor = [UIColor greenColor];
If you are making your app work for devices less than iOS7, you should check it responds to the selector
if([self.navigationController.navigationBar respondsToSelector:@selector(barTintColor)]) {
}
For iOS7 this code works for me when I wish to change the colour of an individual UIBarButtonItem
:
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Title" style:UIBarButtonItemStyleBordered target:self action:nil];
[barButtonItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];
self.navigationItem.leftBarButtonItems = @[barButtonItem];
It might be a good idea to set the tintColor
property on your app's UIWindow
instance instead. If you've got a standard 'accent' colour you're using throughout your app, this will tint every control in the app with that colour.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With