Rob
Rob

Reputation: 1065

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 Button Highlighted 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!

Upvotes: 9

Views: 1172

Answers (3)

gomathi
gomathi

Reputation: 11

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];

Upvotes: 1

Hussain Shabbir
Hussain Shabbir

Reputation: 14995

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

Upvotes: 1

Charan Giri
Charan Giri

Reputation: 1097

// 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];

Upvotes: 1

Related Questions