Setting Bar Button Item color in a custom navigati

2019-01-24 23:48发布

I created a custom navigation bar and a right navigation button using the XIB. This works fine. But I need to to customize the tint color of the right navigation button. At the moment this tint color is the same color as tint color of navigation bar. I need a different color for this right button. Is there any way to change this color?

Thank you.

3条回答
闹够了就滚
2楼-- · 2019-01-25 00:07

In iOS 5 there is 'appearance' feature:

[[UIBarButtonItem appearance] setTintColor:YOUR_COLOR];

查看更多
相关推荐>>
3楼-- · 2019-01-25 00:09

Swift 3.x

UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName : Color.primaryActionColor], for: .normal)
查看更多
爷的心禁止访问
4楼-- · 2019-01-25 00:22

Not to my knowledge, the button inherits the tint color of the navigationBar. What you can do is set a customView for the navigationItem:

This is how you set it with one of the SDK's buttons:

UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(shareButtonHandler:)];

[self.navigationItem setRightBarButtonItem:shareButton];
[shareButton release];

Instead you can do it like this:

UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"yourImage.png" style:UIBarButtonItemStyleBordered target:self action:@selector(customButtonHandler:)]];

To use an image you made in photoshop etc.

There is als an initWithCustomView:UIView or initWithTitle:NSString you can use.

Sorry no "one-line solution" :)

查看更多
登录 后发表回答