我想更改状态栏的背景颜色,背景颜色应与导航栏背景颜色相同,即深灰色 . 我的问题是在使用下面的代码为状态栏和导航栏提供相同的颜色后,我得到了不同的颜色 . 我已经将UIViewControllerBasedStatusBarAppearance设置为NO . 请建议我在哪里做错了,我附上图片供您参考 .
这是我的App委托代码 - didFinishLaunchingWithOptions:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//For changing status bar background color
self.window.backgroundColor = [UIColor darkGrayColor];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
//For changing navigation bar background color
[[UINavigationBar appearance] setBackgroundColor:[UIColor darkGrayColor]];
[[UINavigationBar appearance] setTintColor:[UIColor darkGrayColor]];
3 回答
他们有不同颜色的原因是因为
UIStatusBarStyleLightContent
与[UIColor darkGrayColor]
的颜色不同 .如果状态栏看起来如何调整导航栏颜色,那么您可以设置状态栏颜色:
找出状态栏的RGB值 . (例如,我使用DigitalColor Meter,它说它有R:28,G:28,B:28) .
然后你可以这样做:
您可能需要将半透明度设置为
NO
.如果您只想在某些屏幕上使用它,可以将其添加到
viewDidLoad
方法:首先在VC的viewDidLoad方法中更改statusBar样式
然后在VC的viewDidLoad方法中将
BarTintColor
更改为所需的颜色在你的
AppDelegate
's ' didFinishLaunchingWithOptions:'添加以下内容,它应该有效 .