gpt4 book ai didi

iOS UINavigationBar 色调颜色看起来比颜色集暗

转载 作者:可可西里 更新时间:2023-11-01 03:27:42 26 4
gpt4 key购买 nike

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

//Set Cutom Nav Bar Appearance
[[UINavigationBar appearanceWhenContainedIn:[MyNavigationControllerClass class], nil] setBackgroundImage: nil forBarMetrics: UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[MyNavigationControllerClass class], nil] setBarTintColor: self.tableView.backgroundColor];

当显示导航 Controller 时,预期的颜色是 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];

解决方案

这是从@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];

最佳答案

设置导航栏颜色的方法与您正在做的完全相反。你给它一种色调,没有背景图像。相反,给它一个由所需颜色的矩形组成的背景图像 - 没有色调。

同时将其translucent设置为NO。

关于iOS UINavigationBar 色调颜色看起来比颜色集暗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23090256/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com