9

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!

2
  • for that you have to set the uiimage selected/unselected. Dec 11, 2013 at 10:13
  • 1
    are you found a solution for text color?
    – ArtFeel
    Jun 13, 2014 at 13:04

3 Answers 3

1

// 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];
1
  • I'm actually only looking to tint the text, not set the image!
    – Rob
    Dec 12, 2013 at 16:49
1

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
1
  • I'm only trying to tint the text, not set the background image. :)
    – Rob
    Dec 12, 2013 at 16:50
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.