Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change UIBarbuttonItems Color

How can I set UIBarButtonItem's color to green? I'm using iOS 4, there is no tint property. please help me.

like image 713
user1871678 Avatar asked Dec 03 '12 05:12

user1871678


Video Answer


1 Answers

In iOS 4:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"green.png"] forState:UIControlStateNormal];
button.frame=CGRectMake(0.0, 100.0, 60.0, 30.0);
[button setTitle:@"Green" forState:UIControlStateNormal];
[button addTarget:self action:@selector(yourAction) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithCustomView:button];

Here you need a green image for doing this, you are creating a custom button with this image and set it as the view of UIBarButtonItem.

In iOS 5 you can use:

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

Please check these links for more:

  1. UIAppearance Protocol
  2. User interface customization
like image 121
Midhun MP Avatar answered Oct 31 '22 21:10

Midhun MP