Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tint UIBarButtonItem background color? [duplicate]

I have a UIToolbar that contains 2 buttons. The toolbar has a tint:

toolbar.tintColor = [UIColor colorWithRed:(102.0/255.0) green:(20.0/255.0) blue:(11.0/255.0) alpha:1];

How can I make the buttons have a similar tint color?

like image 727
Sheehan Alam Avatar asked Jul 18 '10 05:07

Sheehan Alam


2 Answers

I found this solution preferable to those listed here: Tint UIButton and UIBarButtonItem. Unlike the accepted answer, it allows you to change the color of UIBarButtonItems independent of the UINavigationBar.

In case the link goes down in the future, the gist of it is that you create a tinted UISegmentedControl (with UISegmentedControlStyleBar) with one segment, then create a UIBarButtonItem using that as its custom view.

In iOS 5, UIBarButtonItem has a tintColor property.

like image 78
titaniumdecoy Avatar answered Sep 21 '22 20:09

titaniumdecoy


The best thing to do is set the tintColor AFTER you add buttons to it, as in iOS 4.0, it no longer updates buttons added to the bars after the tintColor has been set.

like image 26
jrtc27 Avatar answered Sep 19 '22 20:09

jrtc27