Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBarButtonItems selected color won't change properly in iOS 7

So I'm having issues with UIBarButtonItem appearances in iOS 7. There's a property which I can't find any documentation for that seems to set the opacity of navigation bar buttons when pressed, and I don't know how to modify it.

[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
[[UIBarButtonItem appearance] setTitleTextAttributes:@{UITextAttributeTextColor: [UIColor whiteColor]} forState:UIControlStateNormal];
[[UIBarButtonItem appearance] setTitleTextAttributes:@{UITextAttributeTextColor: [UIColor orangeColor]} forState:UIControlStateHighlighted];

For this code, the result I get is shown below.

Normal ButtonHighlighted Button

I'm not sure what's going on here. The first problem is that I can't seem to get the arrow to tint (because there's no setTintColor:forState: method). The second problem is this awful opacity/tint when pressed. Thanks!

like image 872
Rob Avatar asked Dec 11 '13 10:12

Rob


3 Answers

// Customizing the Back Bar Buttons paste this code in appdelegate

UIImage *buttonBack30 = [[UIImage imageNamed:@"button_back_textured_30"]
                         resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 5)];
UIImage *buttonBack24 = [[UIImage imageNamed:@"button_back_textured_24"]
                         resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12, 0, 5)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack30
                                                  forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack24
                                                  forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
like image 79
Charan Giri Avatar answered Oct 15 '22 13:10

Charan Giri


You need to implement this below two method in ios7 for UIBarButtonItem

@property(nonatomic, retain) UIColor *tintColor
- (void)setBackButtonBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics
like image 38
Hussain Shabbir Avatar answered Oct 15 '22 13:10

Hussain Shabbir


Try the below solution it may work

  NSDictionary *attributes = [NSDictionary        dictionaryWithObjectsAndKeys:[UIFont 
fontWithName:@"YOURFONT" size:14], NSFontAttributeName, 
[UIColor whiteColor], NSForegroundColorAttributeName, nil];
  [[UINavigationBar appearance] setTitleTextAttributes:attributes];
like image 1
gomathi Avatar answered Oct 15 '22 11:10

gomathi