在iOS 7中更改条形按钮的颜色

cdu*_*dub 1 uinavigationcontroller rightbarbuttonitem ios ios7

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

// 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;
Run Code Online (Sandbox Code Playgroud)

UINavigationController父级在viewDidLoad中有这个:

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

self.navigationBar.tintColor = [UIColor whiteColor];
self.navigationBar.barTintColor = [UIColor blackColor];
Run Code Online (Sandbox Code Playgroud)

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

Rog*_*son 19

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

self.navigationItem.rightBarButtonItem = nextButton;
self.navigationItem.rightBarButtonItem.tintColor = [UIColor blueColor];
Run Code Online (Sandbox Code Playgroud)

代替

self.navigationItem.rightBarButtonItem.tintColor = [UIColor blueColor];
self.navigationItem.rightBarButtonItem = nextButton;
Run Code Online (Sandbox Code Playgroud)


sha*_*oga 5

如果您希望所有条形按钮具有相同的颜色,则可以使用以下代码行:

self.window.tintColor = [UIColor redColor];
Run Code Online (Sandbox Code Playgroud)

在你的应用程序委托中.