How can I set UIBarButtonItem's
color to green? I'm using iOS 4, there is no tint property. please help me.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With