Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to set the tint color of the back button within a navigation controller, but nothing is working. I have tried

[self.navigationController.backBarButtonItem setTintColor:myColor];
//myColor was previously set

But it stays the default tint

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
958 views
Welcome To Ask or Share your Answers For Others

1 Answer

I believe barButtonItem is read-only. (I'm not too sure about this, someone correct me if I'm wrong)

To give a tint colour to these buttons, this is what I would do:

In your App Delegate, add these lines of code:

UIBarButtonItem *barButtonAppearance = [UIBarButtonItem appearance];
[barButtonAppearance setTintColor:[UIColor redColor]]; // Change to your colour

The first line sets an appearance proxy, so I believe this works too, if you like less code:

[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];

I hope this works for you! (This changes all instances of UIBarButtonItem)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...