我可以通过覆盖 drawRect: 方法来更改 UINavigationController
的背景图像:
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
UIImage *img = [UIImage imageNamed: @"navController.png"];
[img drawInRect:CGRectMake(0, 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, 0, self.frame.size.width, self.frame.size.height)];
self.tintColor = [UIColor colorWithRed:(26/255) green:(103/255) blue:(159/255) alpha:1];
}
@end
如何强制 UINavigationBar
显示我想要的颜色?
注意:我只是遇到了导航 Controller 按钮颜色的问题,因为背景本身设置为图像。
最佳答案
你需要这样做:
self.tintColor = [UIColor colorWithRed:(26.0f/255.0f) green:(103.0f/255.0f) blue:(159.0f/255.0f) alpha:1.0f];
否则,您在进行整数运算时,很可能所有运算结果都为 0。使用浮点运算并获得所需的值。
关于ios - 如何更改 UINavigationController 背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9285191/