如何设置状态栏背景颜色iOS 7

SWT*_*SWT 5 objective-c ipad ios ios7

iOS 6看起来......

在此输入图像描述

同样的方式我想在iOS 7中显示状态栏

看到这个

在此输入图像描述

但我的实际输出(重叠)

我试过跟随逻辑

open your info.plist and set "View controller-based status bar appearance" = NO
Run Code Online (Sandbox Code Playgroud)

它在我的代码中不起作用,,,

Sta*_*lav 17

你必须做两件事.首先是打开你的info.plist设置"View controller-based status bar appearance" = NO

第二个是添加这些行 application:didFinishLaunchingWithOptions

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{   
    self.window.clipsToBounds = YES;
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque];     

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
    {
        self.window.frame =  CGRectMake(20, 0,self.window.frame.size.width-20,self.window.frame.size.height);
        self.window.bounds = CGRectMake(20, 0, self.window.frame.size.width, self.window.frame.size.height);
    } else
    {
        self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
        self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height);
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 您应该注册statusbarorientationchanged通知并在那里使用相同的代码.我不能写你的应用而不是你,我已经给你一个答案了,所以你应该明白这一点并根据你的需要使用它. (8认同)

小智 9

阅读这篇文章:http://www.appcoda.com/customize-navigation-status-bar-ios-7/

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]  

[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x067AB5)];
Run Code Online (Sandbox Code Playgroud)