iOS UINavigationBar色彩颜色显示比颜色设置更暗 [英] iOS UINavigationBar tint color appears darker than color set
问题描述
我为特定导航控制器设置自定义外观:
I am setting a custom appearance for a specific navigation controller:
//Set Cutom Nav Bar Appearance
[[UINavigationBar appearanceWhenContainedIn:[MyNavigationControllerClass class], nil] setBackgroundImage: nil forBarMetrics: UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[MyNavigationControllerClass class], nil] setBarTintColor: self.tableView.backgroundColor];
当显示导航控制器时,预期的颜色是RGB(247,247,247)我已经双重检查也是tableView.background颜色的值时设置的值 - 但它在屏幕上显示为RGB(227,227,227)。
When the navigation controller is displayed, the expected color is RGB(247, 247, 247) - which I have double checked is also the value of the tableView.background color when the value is set - but it appears on screen as RGB( 227, 227, 227). Could there be a different property of UINavigationBar's appearance proxy that is changing the color displayed on screen?
谢谢!
编辑:
此外,如果我直接使用所需的颜色设置barTintColor,屏幕上显示的barTintColor比预期的更暗: / p>
Additionally, if I set the barTintColor directly using the desired color, the barTintColor displayed on screen is still darker than expected:
UIColor* navBarBackgroundColor = [UIColor colorWithRed: (247.0 / 255.0) green: (247.0 / 255.0) blue: (247.0 / 255.0) alpha: 1];
//Set Cutom Nav Bar Appearance
[[UINavigationBar appearanceWhenContainedIn:[MyNavigationControllerClass class], nil] setBackgroundImage: nil forBarMetrics: UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[MyNavigationControllerClass class], nil] setBarTintColor: navBarBackgroundColor];
解决方案
这里是从@ Matt的答案派生的解决方案代码。
Here is the solution code derived from @Matt's answer. Hope it helps someone out
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [self.tableView.backgroundColor CGColor]);
CGContextFillRect(context, rect);
UIImage *navBarImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//Set Cutom Nav Bar Appearance
[[UINavigationBar appearanceWhenContainedIn:[MyNavigationControllerClass class], nil] setBackgroundImage: navBarImage forBarMetrics: UIBarMetricsDefault];
推荐答案
正确设置导航栏颜色的方法是与你在做什么正好相反。你给它一个色彩和没有背景图像。
The way to set the color of a navigation bar exactly is the precise opposite of what you're doing. You are giving it a tint color and no background image. Instead, give it a background image consisting of a rectangle of the desired color - and no tint color.
还要设置半透明
到NO。
这篇关于iOS UINavigationBar色彩颜色显示比颜色设置更暗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!