简体   繁体   English

常见的如何更改uibarbutton颜色

[英]How to change the uibarbutton color in common

I want to have the uibarbutton color change consistent across all classes instead of having it be changed in each class? 我想让uibarbutton颜色在所有类中都保持一致,而不是在每个类中都进行更改? What should I do in the appdelegate ? 我应该在appdelegate做什么?

Here is my code: 这是我的代码:

UIBarButtonItem *random1 = [[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(back:)];
[random1 setTintColor:UIColorFromRGB(0xf63d78)];
self.navigationItem.leftBarButtonItem = random1;

Use UIAppearance proxy for such things. 使用UIAppearance代理进行此类操作。 In your app delegate put the following. 在您的应用程序委托中放入以下内容。

[[UIBarButtonItem appearance] setTintColor:UIColorFromRGB(0xf63d78)];

You should check the Appearance section in the official documentation ( http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIBarButtonItem_Class/Reference/Reference.html ). 您应该检查官方文档( http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIBarButtonItem_Class/Reference/Reference.html )中的“外观”部分。

But what you should do in this case is 但是在这种情况下,您应该做的是

[[UIBarButtonItem appearance] setTintColor:UIColorFromRGB(0xf63d78)];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM