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

发布于 2024-10-04 15:05:16 字数 995 浏览 0 评论 0原文

大家好,

这是一个小细节,但它确实影响了我的应用程序的专业完成度。

我的应用程序遵循选项卡栏的模式,每个选项卡上都有一个导航栏,并且有超过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恋你朝朝暮暮 2024-10-11 15:05:17

之前在 StackOverflow 上已经介绍过了,它指向 此博客,但答案是执行以下操作:

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

It has been covered before on StackOverflow, which points to this blog, but the answer is to do the following:

tabBarController.moreNavigationController.navigationBar.tintColor =
[UIColor orangeColor];
幸福不弃 2024-10-11 15:05:17

向 UINavigationBar 添加一个类别并覆盖 -drawRect:? (然后你可以做一些有趣的事情,比如画一个图像......)

Add a category to UINavigationBar and override -drawRect:? (You can then do fun things like drawing an image instead...)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文