iPhone - 如何在“更多”中设置自定义颜色项目的导航栏?
大家好,
这是一个小细节,但它确实影响了我的应用程序的专业完成度。
我的应用程序遵循选项卡栏的模式,每个选项卡上都有一个导航栏,并且有超过 5 个选项卡,因此有一个“更多”项目。我在导航栏上应用了自定义色调,但我无法找到访问“更多”项目的导航栏来设置色调的方法。谁能告诉我怎么做?
更新...
按照 UINavigationBar
上类别的建议,我使用了这段代码...
@implementation UINavigationBar (UINavigationBar_Additions)
- (void)drawRect:(CGRect)rect {
UIColor *color = [UIColor colorWithRed:0.862745098039216
green:0.568627450980392
blue:0.098039215686275
alpha:1];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColor(context, CGColorGetComponents( [color CGColor]));
CGContextFillRect(context, rect);
[self setBarStyle:UIBarStyleBlack];
[self setTintColor:color];
}
@end
除了苹果关于不重写这样的隐藏方法的警告(出于对我来说似乎有意义的原因)之外,它还丢失 UINavigationBar 上的渐变 &我宁愿保留我当前在 viewDidLoad 中设置色调的方法所做的事情。
关于如何吃蛋糕和蛋糕的任何建议也吃它。
蒂亚,佩德罗:)
G'day All
This is a small detail but it does affect the professional finish of my app.
My app follows the pattern of a tab bar with a navigation bar on each tab with more than 5 tabs hence a "More" item. I have a custom tint applied to the navigation bar but I haven't been able to find a way to access the navigation bar of the "More" item to set the tint on that. Can anyone tell me how?
Update...
Following the suggestion of a category on UINavigationBar
I used this code...
@implementation UINavigationBar (UINavigationBar_Additions)
- (void)drawRect:(CGRect)rect {
UIColor *color = [UIColor colorWithRed:0.862745098039216
green:0.568627450980392
blue:0.098039215686275
alpha:1];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColor(context, CGColorGetComponents( [color CGColor]));
CGContextFillRect(context, rect);
[self setBarStyle:UIBarStyleBlack];
[self setTintColor:color];
}
@end
Aside from Apple's warning (for reasons that seem to make sense to me) about not overriding hidden methods like this it also loses the gradient on the UINavigationBar
& I'd rather keep that which my current approach of setting the tint in viewDidLoad
does.
Any suggestions as to how I can have my cake & eat it too.
TIA, Pedro :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
之前在 StackOverflow 上已经介绍过了,它指向 此博客,但答案是执行以下操作:
It has been covered before on StackOverflow, which points to this blog, but the answer is to do the following:
向 UINavigationBar 添加一个类别并覆盖 -drawRect:? (然后你可以做一些有趣的事情,比如画一个图像......)
Add a category to UINavigationBar and override -drawRect:? (You can then do fun things like drawing an image instead...)