Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the font color of a UIBarButton item?

Tags:

I want to change the color to red.

like image 736
Sheehan Alam Avatar asked Jul 22 '10 22:07

Sheehan Alam


People also ask

How can you change the color of text?

Go to Format > Font > Font. + D to open the Font dialog box. Select the arrow next to Font color, and then choose a color. Select Default and then select Yes to apply the change to all new documents based on the template.

How do I change the color of my UIBarButtonItem?

In iOS 5 you can use: [[UIBarButtonItem appearance] setTintColor:[UIColor greenColor]]; Please check these links for more: UIAppearance Protocol.


1 Answers

I found a simpler way to just change the color of title: iOS7:

UIBarButtonItem *button =   [[UIBarButtonItem alloc] initWithTitle:@"Title"                                    style:UIBarButtonItemStyleBordered                                   target:nil                                   action:nil]; [button setTitleTextAttributes:           [NSDictionary dictionaryWithObjectsAndKeys:                 [UIColor redColor], NSForegroundColorAttributeName,nil]                                              forState:UIControlStateNormal]; 

and prior iOS7:

UIBarButtonItem *button =    [[UIBarButtonItem alloc] initWithTitle:@"Title"                                     style:UIBarButtonItemStyleBordered                                    target:nil                                    action:nil]; [button setTitleTextAttributes:           [NSDictionary dictionaryWithObjectsAndKeys:                 [UIColor redColor], UITextAttributeTextColor,nil]                                      forState:UIControlStateNormal]; 
like image 193
Gavy Avatar answered Oct 14 '22 14:10

Gavy