Reputation: 153
How can I set UIBarButtonItem's
color to green? I'm using iOS 4, there is no tint property. please help me.
Upvotes: 15
Views: 16415
Reputation: 3802
In Swift 4
This is how you can add your custom color to UIBarButtonItem
let barButtonItem = UIBarButtonItem.init(
title: "Paired",
style: .done,
target: self,
action: #selector(self.myAction(sender:))
)
barButtonItem.tintColor = UIColor.init(red: 247/255, green: 65/255, blue: 126/255, alpha: 1.0)
self.navigationItem.rightBarButtonItem = barButtonItem
Upvotes: 2
Reputation: 1551
I know this is an old question, but in case anyone is using a customView
, you can try:
myButton.customView.tintColor = [UIColor blackColor];
Upvotes: 0
Reputation: 107121
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:
Upvotes: 17
Reputation: 3738
Please try the below code.
self.navigationController.navigationBar.tintColor = [UIColor greenColor];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:NULL];
Upvotes: 2