iOS UINavigationBar色调颜色比颜色设置更暗

Gla*_*vid 7 colors uinavigationbar ios

我正在为特定的导航控制器设置自定义外观:

//Set Cutom Nav Bar Appearance
[[UINavigationBar appearanceWhenContainedIn:[MyNavigationControllerClass class], nil] setBackgroundImage: nil forBarMetrics: UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[MyNavigationControllerClass class], nil] setBarTintColor: self.tableView.backgroundColor];
Run Code Online (Sandbox Code Playgroud)

当显示导航控制器时,预期的颜色是RGB(247,247,247) - 我已经双重检查也是设置值时tableView.background颜色的值 - 但它在屏幕上显示为RGB(227 ,227,227).UINavigationBar的外观代理是否有不同的属性可以改变屏幕上显示的颜色?

谢谢!

编辑:

此外,如果我使用所需的颜色直接设置barTintColor,屏幕上显示的barTintColor仍然比预期更暗:

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];
Run Code Online (Sandbox Code Playgroud)

以下是来自@Matt答案的解决方案代码.希望它可以帮助别人

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];
Run Code Online (Sandbox Code Playgroud)

mat*_*att 14

准确设置导航栏颜色的方式与您正在进行的操作完全相反.你给它一个色调,没有背景图像.相反,给它一个由所需颜色的矩形组成的背景图像 - 没有色调.

同时将其设置translucent为NO.