4ma*_*oud 4 iphone xcode objective-c uinavigationbar ios
我可以UINavigationController通过覆盖drawRect:方法来改变背景图像:
@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
Run Code Online (Sandbox Code Playgroud)
背景是我打算成为的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
Run Code Online (Sandbox Code Playgroud)
我怎么强迫UINavigationBar显示我想要的颜色?
注意:我只对导航控制器按钮颜色有问题,因为背景本身设置为图像.
mat*_*way 10
你需要这样做:
self.tintColor = [UIColor colorWithRed:(26.0f/255.0f) green:(103.0f/255.0f) blue:(159.0f/255.0f) alpha:1.0f];
Run Code Online (Sandbox Code Playgroud)
否则你正在进行整数运算,你最终可能会得到0.使用浮点运算,您可以获得所需的值.
这对我有用
self.navigationController.navigationBar.backgroundColor= [UIColor colorWithRed:57.0/255.0 green:158.0/255 blue:209.0/255 alpha:1.0];
Run Code Online (Sandbox Code Playgroud)