iOS 8使状态栏为黑色而非半透明

iOS 8使状态栏为黑色而非半透明,ios,objective-c,iphone-6,uistatusbar,Ios,Objective C,Iphone 6,Uistatusbar,因此,我的应用程序中的状态栏当前如下所示: 我宁愿它看起来像这样: 所以它是黑白相间的。目前,它在这个特定的屏幕上不起作用,因为背景不是黑色的。我已经在pList中将状态栏样式设置为UIStatusBarStyleLightContent 我还要补充一点,视图是初始的ViewController,它没有嵌入UINavigationController: 编辑:这不是重复,因为以前的大多数解决方案已经过时 您只需将其设置为“亮”,然后在其后面抛出一个视图即可。如果在应用程序中允许设备轮换,您还

因此,我的应用程序中的状态栏当前如下所示:

我宁愿它看起来像这样:

所以它是黑白相间的。目前,它在这个特定的屏幕上不起作用,因为背景不是黑色的。我已经在pList中将
状态栏样式设置为
UIStatusBarStyleLightContent

我还要补充一点,视图是初始的ViewController,它没有嵌入
UINavigationController


编辑:这不是重复,因为以前的大多数解决方案已经过时

您只需将其设置为“亮”,然后在其后面抛出一个视图即可。如果在应用程序中允许设备轮换,您还必须考虑设备轮换。
Swift:

override func viewDidLoad() {
    super.viewDidLoad()

    let statusBG = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 21))
    statusBG.backgroundColor = UIColor.blackColor()
    view.addSubview(statusBG)
}
- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *statusBG = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 21)];
    statusBG.backgroundColor = [UIColor blackColor];
    [self.view addSubview:statusBG];
}
目标-C:

override func viewDidLoad() {
    super.viewDidLoad()

    let statusBG = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 21))
    statusBG.backgroundColor = UIColor.blackColor()
    view.addSubview(statusBG)
}
- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *statusBG = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 21)];
    statusBG.backgroundColor = [UIColor blackColor];
    [self.view addSubview:statusBG];
}

您可以将其设置为“亮”,然后在其后面抛出一个视图。如果在应用程序中允许设备轮换,您还必须考虑设备轮换。
Swift:

override func viewDidLoad() {
    super.viewDidLoad()

    let statusBG = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 21))
    statusBG.backgroundColor = UIColor.blackColor()
    view.addSubview(statusBG)
}
- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *statusBG = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 21)];
    statusBG.backgroundColor = [UIColor blackColor];
    [self.view addSubview:statusBG];
}
目标-C:

override func viewDidLoad() {
    super.viewDidLoad()

    let statusBG = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 21))
    statusBG.backgroundColor = UIColor.blackColor()
    view.addSubview(statusBG)
}
- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *statusBG = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 21)];
    statusBG.backgroundColor = [UIColor blackColor];
    [self.view addSubview:statusBG];
}

您可以将其设置为“亮”,然后在其后面抛出一个视图。如果在应用程序中允许设备轮换,您还必须考虑设备轮换。
Swift:

override func viewDidLoad() {
    super.viewDidLoad()

    let statusBG = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 21))
    statusBG.backgroundColor = UIColor.blackColor()
    view.addSubview(statusBG)
}
- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *statusBG = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 21)];
    statusBG.backgroundColor = [UIColor blackColor];
    [self.view addSubview:statusBG];
}
目标-C:

override func viewDidLoad() {
    super.viewDidLoad()

    let statusBG = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 21))
    statusBG.backgroundColor = UIColor.blackColor()
    view.addSubview(statusBG)
}
- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *statusBG = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 21)];
    statusBG.backgroundColor = [UIColor blackColor];
    [self.view addSubview:statusBG];
}

您可以将其设置为“亮”,然后在其后面抛出一个视图。如果在应用程序中允许设备轮换,您还必须考虑设备轮换。
Swift:

override func viewDidLoad() {
    super.viewDidLoad()

    let statusBG = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 21))
    statusBG.backgroundColor = UIColor.blackColor()
    view.addSubview(statusBG)
}
- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *statusBG = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 21)];
    statusBG.backgroundColor = [UIColor blackColor];
    [self.view addSubview:statusBG];
}
目标-C:

override func viewDidLoad() {
    super.viewDidLoad()

    let statusBG = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 21))
    statusBG.backgroundColor = UIColor.blackColor()
    view.addSubview(statusBG)
}
- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *statusBG = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 21)];
    statusBG.backgroundColor = [UIColor blackColor];
    [self.view addSubview:statusBG];
}

因为在iOS 6或更早版本上,状态栏不是半透明的,所以最好根据iOS版本进行设置。在
视图中加载

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 20)];
    statusBarView.backgroundColor=[UIColor blackColor];
    [self.view addSubview:statusBarView];
}
其中,
系统版本大于或等于

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

这将为您提供一个黑色背景和白色文本的状态栏。

因为在iOS 6或更早版本上,状态栏不是半透明的,因此最好根据iOS版本执行此操作。在
视图中加载

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 20)];
    statusBarView.backgroundColor=[UIColor blackColor];
    [self.view addSubview:statusBarView];
}
其中,
系统版本大于或等于

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

这将为您提供一个黑色背景和白色文本的状态栏。

因为在iOS 6或更早版本上,状态栏不是半透明的,因此最好根据iOS版本执行此操作。在
视图中加载

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 20)];
    statusBarView.backgroundColor=[UIColor blackColor];
    [self.view addSubview:statusBarView];
}
其中,
系统版本大于或等于

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

这将为您提供一个黑色背景和白色文本的状态栏。

因为在iOS 6或更早版本上,状态栏不是半透明的,因此最好根据iOS版本执行此操作。在
视图中加载

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 20)];
    statusBarView.backgroundColor=[UIColor blackColor];
    [self.view addSubview:statusBarView];
}
其中,
系统版本大于或等于

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

这将为您提供一个黑色背景和白色文本的状态栏。

在您的AppDelegate应用程序中,IDFinishLaunchingWithOptions方法编写以下代码。这有助于所有视图控制器。您无需在每个视图控制器中添加代码

[UIApplication sharedApplication].statusBarHidden=NO;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) 
{ 
  [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  [application setStatusBarHidden:NO];
  self.window.clipsToBounds=YES;
  self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}
else
{
  self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  [application setStatusBarHidden:NO];
  self.window.clipsToBounds=YES;
  self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}
然后你可以输入你的projectname.plist

Status bar is initially hidden is NO
View controller-based status bar appearance is YES

在AppDelegate应用程序中,使用Options方法编写以下代码。这有助于所有视图控制器。无需在每个视图控制器中添加代码

[UIApplication sharedApplication].statusBarHidden=NO;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) 
{ 
  [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  [application setStatusBarHidden:NO];
  self.window.clipsToBounds=YES;
  self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}
else
{
  self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  [application setStatusBarHidden:NO];
  self.window.clipsToBounds=YES;
  self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}
然后你可以输入你的projectname.plist

Status bar is initially hidden is NO
View controller-based status bar appearance is YES

在AppDelegate应用程序中,使用Options方法编写以下代码。这有助于所有视图控制器。无需在每个视图控制器中添加代码

[UIApplication sharedApplication].statusBarHidden=NO;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) 
{ 
  [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  [application setStatusBarHidden:NO];
  self.window.clipsToBounds=YES;
  self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}
else
{
  self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  [application setStatusBarHidden:NO];
  self.window.clipsToBounds=YES;
  self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}
然后你可以输入你的projectname.plist

Status bar is initially hidden is NO
View controller-based status bar appearance is YES

在AppDelegate应用程序中,使用Options方法编写以下代码。这有助于所有视图控制器。无需在每个视图控制器中添加代码

[UIApplication sharedApplication].statusBarHidden=NO;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) 
{ 
  [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  [application setStatusBarHidden:NO];
  self.window.clipsToBounds=YES;
  self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}
else
{
  self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  [application setStatusBarHidden:NO];
  self.window.clipsToBounds=YES;
  self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}
然后你可以输入你的projectname.plist

Status bar is initially hidden is NO
View controller-based status bar appearance is YES

@Chrislowik没有,因为这些是2011年的回复,在iOS 8年内不再有效,你是对的。您应该将状态栏设置为“轻内容”,并在其后面放置一个黑色视图。21分,如果我没记错的话。@ChrisSlowik没有,因为这些是2011年的回复,在iOS 8yea中不再有效。你是对的。您应该将状态栏设置为“轻内容”,并在其后面放置一个黑色视图。21分,如果我没记错的话。@ChrisSlowik没有,因为这些是2011年的回复,在iOS 8yea中不再有效。你是对的。您应该将状态栏设置为“轻内容”,并在其后面放置一个黑色视图。21分,如果我没记错的话。@ChrisSlowik没有,因为这些是2011年的回复,在iOS 8yea中不再有效。你是对的。您应该将状态栏设置为“轻内容”,并在其后面放置一个黑色视图。如果我没记错的话是21pt。但这在iPhoneX上很难看。如何在iPhoneX上解决这个问题?这是一个过时的设计模式,应该在iOS11上避免。无法修复丑陋。有关iPhone X设计的更多详细信息,请查看苹果的人机界面指南。但这在iPhoneX上很难看。如何在iPhoneX上解决这个问题?这是一个过时的设计模式,应该在iOS11上避免。无法修复丑陋。有关iPhone X设计的更多详细信息,请查看苹果的人机界面指南。但这在iPhoneX上很难看。如何在iPhoneX上解决这个问题?这是一个过时的设计模式,应该在iOS11上避免。无法修复丑陋。有关iPhone X设计的更多详细信息,请查看苹果的人机界面指南。但这在iPhoneX上很难看。如何在iPhoneX上解决这个问题?这是一个过时的设计模式,应该在iOS11上避免。无法修复丑陋。有关iPhone X设计的更多详细信息,请查看苹果的人机界面指南。