navigationBar 的自定义 barTintColor
Custom barTintColor for navigationBar
我正在尝试为我的应用程序导航栏获取自定义颜色,但显示不正确。我需要使用的确切颜色的十六进制代码是蓝色#023883。我从这个网站查找了 rbg 百分比:http://www.colorhexa.com/023883,百分比是:rgb(0.8%,22%,51.4%)。我把它放在我的代码中是这样的:
self.navigationController.navigationBar.barTintColor = [UIColor
colorWithRed:0.8 green:22 blue:51.4 alpha:1.0];
self.navigationController.navigationBar.titleTextAttributes =
@{NSForegroundColorAttributeName : [UIColor lightGrayColor]};
self.navigationController.navigationBar.backgroundColor = [UIColor
whiteColor];
self.navigationController.navigationBar.translucent = YES;
我还尝试实现允许使用输入十六进制代码的颜色值的代码,但这也不起作用。我还有其他方法可以获得这种颜色吗? (我也试着只把蓝色设为 100,但它仍然不够暗)
你忘了 % ,应该是
self.navigationController.navigationBar.barTintColor = [UIColor
colorWithRed:0.008 green:0.22 blue:0.514 alpha:1.0];
编辑,关于如何让statusBar变白
- 在info.plist文件
View controller-based status bar appearance
中将此项设为NO。点击右边的plus
图标Information 属性 List,然后你在新行中点击一个V
,它会自动补全,第一个就是这个key
在应用委托中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[application setStatusBarStyle:UIStatusBarStyleLightContent];
return YES;
}
您使用的 colorWithRed:green:blue:alpha
有误。
您应该输入百分比(在您的情况下为 0.8、22 和 51.4),但输入方式有误。
请改为输入 0.008、0.22 和 0.514:
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.008 green:0.22 blue:0.514 alpha:1.0];
第一步
Select 你的 NavigationController
步骤 - 2
选择 Navigation bar
第 3 步
可以获取导航栏属性
步骤-4在这里你可以改变Title
、Font
、Background color
等
statusBar - 透明
Target
--> Genral
--> U 得到如下结果变化 Status Bar Style
--> Light
,请照图
不要忘记在 plist
中设置 NO
字符串名称是 --> View controller-based status bar appearance
我正在尝试为我的应用程序导航栏获取自定义颜色,但显示不正确。我需要使用的确切颜色的十六进制代码是蓝色#023883。我从这个网站查找了 rbg 百分比:http://www.colorhexa.com/023883,百分比是:rgb(0.8%,22%,51.4%)。我把它放在我的代码中是这样的:
self.navigationController.navigationBar.barTintColor = [UIColor
colorWithRed:0.8 green:22 blue:51.4 alpha:1.0];
self.navigationController.navigationBar.titleTextAttributes =
@{NSForegroundColorAttributeName : [UIColor lightGrayColor]};
self.navigationController.navigationBar.backgroundColor = [UIColor
whiteColor];
self.navigationController.navigationBar.translucent = YES;
我还尝试实现允许使用输入十六进制代码的颜色值的代码,但这也不起作用。我还有其他方法可以获得这种颜色吗? (我也试着只把蓝色设为 100,但它仍然不够暗)
你忘了 % ,应该是
self.navigationController.navigationBar.barTintColor = [UIColor
colorWithRed:0.008 green:0.22 blue:0.514 alpha:1.0];
编辑,关于如何让statusBar变白
- 在info.plist文件
View controller-based status bar appearance
中将此项设为NO。点击右边的plus
图标Information 属性 List,然后你在新行中点击一个V
,它会自动补全,第一个就是这个key 在应用委托中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [application setStatusBarStyle:UIStatusBarStyleLightContent]; return YES; }
您使用的 colorWithRed:green:blue:alpha
有误。
您应该输入百分比(在您的情况下为 0.8、22 和 51.4),但输入方式有误。
请改为输入 0.008、0.22 和 0.514:
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.008 green:0.22 blue:0.514 alpha:1.0];
第一步
Select 你的 NavigationController
步骤 - 2
选择 Navigation bar
第 3 步
可以获取导航栏属性
步骤-4在这里你可以改变Title
、Font
、Background color
等
statusBar - 透明
Target
--> Genral
--> U 得到如下结果变化 Status Bar Style
--> Light
,请照图
不要忘记在 plist
中设置 NO
字符串名称是 --> View controller-based status bar appearance