Change the status bar background color color past

2019-02-03 05:43发布

I want to change background color of status bar on iOS 7, and I'm using this code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [UIApplication sharedApplication].statusBarHidden = NO;

        self.window.clipsToBounds = YES;
        [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];
        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);

        ...
        ...


}

When I write this it shows the status bar with a black background; I want it to have a red background.

How can change the color of the status bar to have a red background instead of black?

8条回答
ら.Afraid
2楼-- · 2019-02-03 06:37

in AppDelegate use

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

and in project info.plist file

set flag NO to View controller-based status bar appearance in app.

查看更多
别忘想泡老子
3楼-- · 2019-02-03 06:39

In iOS 7 and later, the status bar is transparent. Set the backgroundColor of your view to the color you want for the status bar.

Or, you can add a 20px-high subview with red color at the top of your view.

See the Apple Transition Guide for more.

Also, make sure that your preferredStatusBarStyle is UIStatusBarStyleLightContent. and in your Info.plist set "View controller-based status bar appearance" to "NO".

查看更多
登录 后发表回答