简体   繁体   English

iPhone-如何在“更多”项目的导航栏中设置自定义颜色?

[英]iPhone - How to set custom color in the “More” item's navigation bar?

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. 我的应用程序遵循选项卡栏的模式,每个选项卡上都有一个导航栏,其中有5个以上的选项卡,因此是“更多”项。 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... 遵循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

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. 除了苹果警告(出于对我而言似乎有意义的原因)关于不重写此类隐藏方法的警告外,它还失去了UINavigationBar上的渐变效果,我宁愿保留我当前在viewDidLoad中设置色调的方法。

Any suggestions as to how I can have my cake & eat it too. 关于我如何可以吃蛋糕的任何建议。

TIA, Pedro :) TIA,佩德罗:)

It has been covered before on StackOverflow , which points to this blog , but the answer is to do the following: 指向此博客的 StackOverflow之前已经进行了介绍,但是答案是要执行以下操作:

tabBarController.moreNavigationController.navigationBar.tintColor =
[UIColor orangeColor];

Add a category to UINavigationBar and override -drawRect:? 向UINavigationBar添加类别并覆盖-drawRect :? (You can then do fun things like drawing an image instead...) (然后,您可以做一些有趣的事情,例如绘制图像……)

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

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