0

I want to set a background color like Facebook app's statusbar, but I can't find a way to fix it in Apple's documents. Is there any advice for me?

nhgrif
  • 61,578
  • 25
  • 134
  • 173
wupeng
  • 3
  • 1
  • 4

3 Answers3

4

You cannot change the status bar color, as it has not background to change.

However you could create a view on 20px height and place it behind the status bar.

If you have a UINavigationBar, you could either remove the background color of a UINavigationBar or add a subview to the UINavigationBar with a height on 20px and give it the color of the status bar.

I found this on github, you can inspect the code and find out how to change the color for the top 20px https://github.com/remirobert/RRMaterialNavigationBar

A.Roe
  • 973
  • 3
  • 15
  • 34
1

As they say, you can generate a 20px view with the color you want.

First you'll need to hide the Status bar in the info.plist: - Set View controller-based status bar appearance to NO

Then you can set the new color with something like this in the AppDelegate:

UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 20)];
view.backgroundColor=[UIColor blackColor];
[self.window.rootViewController.view addSubview:view];
Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216
Luciano LB
  • 53
  • 6
0

One solution consist in these two lines of code in your applicationDidFinishLaunching, in appDelegate:

UIApplication.sharedApplication().keyWindow?.backgroundColor = UIColor.greenColor()
UINavigationBar.appearance().clipsToBounds = true

This will basically change the statusBar background color for all of your app's viewControllers, you have to set also the background color to clearColor() for all of your viewControllers.

Marco M
  • 1,215
  • 12
  • 12