在iOS 7中更改条形按钮的颜色 [英] Change the color of a bar button in iOS 7

查看:118
本文介绍了在iOS 7中更改条形按钮的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在包含视图的viewDidLoad中有以下代码:

I have the following code in my viewDidLoad of my containing view:

// Now add the next button
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self action:@selector(self)];
self.navigationItem.rightBarButtonItem.tintColor = [UIColor blueColor];
self.navigationItem.rightBarButtonItem = nextButton;

UINavigationController父级在viewDidLoad中有这个:

The UINavigationController parent has this in viewDidLoad:

[super viewDidLoad];
// Do any additional setup after loading the view.

self.navigationBar.tintColor = [UIColor whiteColor];
self.navigationBar.barTintColor = [UIColor blackColor];

如何自定义rightBar按钮以更改背景颜色和文本颜色?

How do I just customize the rightBar button to change the background color and maybe the text color?

推荐答案

分配按钮后,必须在按钮上设置tintColor属性。

You have to set the tintColor property on the button after you assign the button.

self.navigationItem.rightBarButtonItem = nextButton;
self.navigationItem.rightBarButtonItem.tintColor = [UIColor blueColor];

而不是

self.navigationItem.rightBarButtonItem.tintColor = [UIColor blueColor];
self.navigationItem.rightBarButtonItem = nextButton;

这篇关于在iOS 7中更改条形按钮的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆