【发布时间】:2011-08-01 16:08:50
【问题描述】:
在我的应用程序中,我将覆盖 AppDelegate 中的 uinavigationbar 颜色以在整个应用程序中创建此颜色:
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
UIColor *color = [UIColor colorWithRed:0.16
green:0.20
blue:0.32
alpha:1];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColor(context, CGColorGetComponents( [color CGColor]));
CGContextFillRect(context, rect);
[self setBarStyle:UIBarStyleBlack];
[self setTintColor:color];
}
但是,在我的一个观点中,我想将其中一个导航栏项目的颜色更改为另一种颜色,与上面的全局颜色不同,但仅限于其中一个项目 - 栏颜色应该保持不变相同(推理 - 我想要一个绿色的导航栏项目和一个“开启”文本,并根据用户输入将其更改为红色并带有一个“关闭”文本)。
我尝试通过以下方式覆盖视图中按钮的颜色,但它似乎没有做任何事情。
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setTintColor:[UIColor greenColor]];
}
有没有人有建议(或更好的方法)来实现这一点?
干杯。
【问题讨论】:
标签: iphone objective-c uinavigationcontroller uinavigationbar uinavigationitem