ios – 如何更改UINavigationController背景颜色?

ios – 如何更改UINavigationController背景颜色?,第1张

概述我可以通过覆盖drawRect:方法来更改UINavigationController的背景图像: @implementation UINavigationBar (UINavigationBarCategory)- (void)drawRect:(CGRect)rect { UIImage *img = [UIImage imageNamed: @"navController.p 我可以通过覆盖drawRect:方法来更改UINavigationController的背景图像:

@implementation UINavigationbar (UINavigationbarcategory)- (voID)drawRect:(CGRect)rect {    UIImage *img  = [UIImage imagenamed: @"navController.png"];    [img drawInRect:CGRectMake(0,self.frame.size.wIDth,self.frame.size.height)];        self.tintcolor = [UIcolor bluecolor];}@end

背景是我想要的和tintcolor,但是当试图设置UIcolor类中不存在的颜色时,它会失败并显示奇怪的颜色:

@implementation UINavigationbar (UINavigationbarcategory)- (voID)drawRect:(CGRect)rect {    UIImage *img  = [UIImage imagenamed: @"navController.png"];    [img drawInRect:CGRectMake(0,self.frame.size.height)];        self.tintcolor = [UIcolor colorWithRed:(26/255) green:(103/255) blue:(159/255)                      Alpha:1];}@end

如何强制UINavigationbar显示我想要的颜色?

注意:我只对导航控制器按钮颜色有问题,因为背景本身设置为图像.

解决方法 你需要这样做:

self.tintcolor = [UIcolor colorWithRed:(26.0f/255.0f) green:(103.0f/255.0f) blue:(159.0f/255.0f) Alpha:1.0f];

否则你正在进行整数运算,你最终可能会得到0.使用浮点运算,您可以获得所需的值.

总结

以上是内存溢出为你收集整理的ios – 如何更改UINavigationController背景颜色?全部内容,希望文章能够帮你解决ios – 如何更改UINavigationController背景颜色?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1036366.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存