Ios7 xcode 5 GM: UIBarButtonItem color and selected part of UISegmentedControl on iOS 6 device keep the default color

I am porting an ios6 application to ios7 sdk (with Xcode 5 and mavericks) and I tried changing the color of the UIBarButtonItem, here is what I am trying to do:

self.navigationController.navigationBar.tintColor 

- change color for panel, but not for elements

 [[UINavigationBar appearance] setTintColor:[UIColor greenColor]]; [[UIBarButtonItem appearance] setTintColor:[UIColor greenColor]]; 

- does not work, same wrong color

 self.navigationItem.rightBarButtonItem.tintColor = [UIColor greenColor]; self.navigationItem.leftBarButtonItem.tintColor = [UIColor greenColor]; 

- does not work, same wrong color

  UIBarButtonItem *close = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close",@"") style:UIBarButtonItemStyleDone target:self action:@selector(closeAddressBook:)]; close.tintColor = [UIColor greenColor]; 

- does not work, same wrong color

  for self.filterSegment.tintColor = [UIColor greenColor] where UISegmentedControl *filterSegment; 

I see an unselected segment with the correct color, but the selected segment has the same wrong color.

any ideas?

+8
iphone
source share
6 answers

It turned out what needs to be done thanks to WWDC 2013 - Customizing App Apps for iOS 7.

 self.navigationController.navigationBar.tintColor = [UIColor redColor]; 

This will be filtered out for other views in your application, so place them on the home screen, and if you click on the next screen, you will see that the back button is also red.

To change the color of the navigation bar, use

 self.navigationController.navigationBar.barTintColor = [UIColor greenColor]; 

If you make your application work on devices smaller than iOS7, you should check if it responds to the selector

 if([self.navigationController.navigationBar respondsToSelector:@selector(barTintColor)]) { } 
+15
source share

For iOS7, this code works for me when I want to change the color 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]; 
+10
source share

It might be nice to set the tintColor property in your UIWindow application instead. If you have a standard accent color that you use throughout the application, this will set off every control in the application with that color.

+1
source share

1 - In iOS 7 tintColor property tintColor no longer used to set the panel color. Instead, use the barTintColor property to change the background color. You can paste the following code into didFinishLaunchingWithOptions: from AppDelegate.m .

 [[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]]; 

2 - In iOS 7, all panel buttons are borderless. The back button now represents a chevron plus the title of the previous screen (or simply displays "Back as the name of the button if the title of the previous screen is zero"). To hone the back button, you can change the tintColor property, which provides a quick and easy way to drop your application with a custom color. The following is an example code snippet:

 [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; 
+1
source share

self.navigationController.navigationBar.tintColor = [UIColor redColor];

This is a way to set the color for the lining.

Just a note for ppl, which developed the application using iOS 6, we used the above code to set the color of Nav Bar, so by mistake, if you did not delete the previous setting, you will not see a change to the "Back" button.

0
source share

I finally figured out how to solve this problem. After installing the button, you need to wait 5-7 ms (in the case of iPhone 5s).

 UIBarButtonItem *button=[[UIBarButtonItem alloc]... self.navigationItem.rightBarButtonItem=button; [button performSelector:@selector(setTintColor:) withObject:[UIColor blueColor] afterDelay:0.1]; 

You should not set the color before setting rightBarButtonItem . It should work for both iOS 6 and 7.

-2
source share

All Articles