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?
3 Answers
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

- 973
- 3
- 15
- 34
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];

- 19,381
- 28
- 133
- 216

- 53
- 6
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.

- 1,215
- 12
- 12
-
I failed to set the color of the `keyWindow` with this method – Bright May 19 '17 at 03:14