Search code examples
iphoneiosuibarbuttonitemuinavigationitem

How to change the uibarbutton color in common


I want to have the uibarbutton color change consistent across all classes instead of having it be changed in each class? What should I do in the appdelegate?

Here is my code:

UIBarButtonItem *random1 = [[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(back:)];
[random1 setTintColor:UIColorFromRGB(0xf63d78)];
self.navigationItem.leftBarButtonItem = random1;

Solution

  • You should check the Appearance section in the official documentation (http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIBarButtonItem_Class/Reference/Reference.html).

    But what you should do in this case is

    [[UIBarButtonItem appearance] setTintColor:UIColorFromRGB(0xf63d78)];