**
- You must take care of these three things:
**
**- In info.plist file**
Set UIViewControllerBasedStatusBarAppearance to YES
**- In your view controller** in which you want change color of status bar
add this [self setNeedsStatusBarAppearanceUpdate] in viewDidLoad
**- Lastly, add this method**
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
Note: If you want to set color of statusBar for all the View Controllers then steps are
**- In info.plist file**
Set UIViewControllerBasedStatusBarAppearance to YES
**- Then add this in appDelegate**
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; // **It is deprecated in iOS 9**
6 回答
要在 Info.plist 文件中添加此键值对:
默认(黑色)值为
UIStatusBarStyleDefault
.您还可以将
~iphone
或~ipad
追加到该键 .有2 steps:
这通常是开发人员知道如何操作 - 在目标设置>常规>状态栏样式>更改为灯光下 . 这将影响Info.plist包含
UIStatusBarStyleLightContent
.This step is often missed out - 在Info.plist中,添加
View controller-based status bar appearance
并设置为NO只需在您想要的任何视图或文件中定义此方法:
就我而言,
UIStatusBarStyleLightContent
不是一个可能的选择 . 我将Transparent black style (alpha of 0.5)
设置为我的.plist中的键Status bar style
的值,结果是一个白色状态栏 .适用于iOS7和iOS8
您需要在 Info.plist 文件属性中设置键
Status bar style
:为白色状态栏设置
Opaque black style
或Transparent black style (alpha of 0.5)
设置
Gray style (default)
以设置黑色状态栏颜色 .看起来您为状态栏设置了背景样式,XCode了解状态栏的哪种颜色需要选择 . 黑暗的背景 - 白色状态栏,浅色背景 - 黑色状态栏