How to change status bar background color - ios

Is there way to change the background color of status bar right now it show white with black icons of battery i want the color black here is the code i am using in viewDidLoad
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;

Set UIViewControllerBasedStatusBarAppearance to NO. Call
[[UIApplication sharedApplication]
setStatusBarStyle:UIStatusBarStyleLightContent];
For more details...check this link
EDIT: try adding this
self.extendedLayoutIncludesOpaqueBars = YES;

in iOS 7 the status Bar is transparent. Make sure the background view is Dark if you are setting UIStatusBarStyleLightContent
For more info You can check the Apple UITransition Guide

1) set the UIViewControllerBasedStatusBarAppearance to YES in the plist
2) in viewDidLoad do a [self setNeedsStatusBarAppearanceUpdate];
3) add the following method:
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
also check developers-guide-to-the-ios-7-status-bar

Related

iPhone 6/6 plus show status bar

Only with iphone 6/6 plus the status bar is blank, I don't see anything while on iphone 5, ipad 3 (both with iOS8) all work perfectly, I add:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
on
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
I also add: View controller-based status bar appearance NO but nothing, where is the mistake?
There could be two possibilities.
Either this property is present in your plist. (Status bar style : UIStatusBarStyleLightContent) and your viewcontroller's background is also whiteColor.
or
Your status bar is set to be hidden initially or by the code [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
Kindly check your view background. It could be either black & the statusBar is also Default or it background is white & statusBar is LightContent.
Hope that helps.
Try to add UIStatusBarHidden (Status bar is initially hidden) with value YES in your Info.plist
From the comment above, you mentioned that you want to show the Status bar.
If so, put the following code inside whichever view controller that you want the status bar to appear.
- (BOOL)prefersStatusBarHidden {
return NO;
}
For the PList:
View controller-based status bar appearance: NO (means that you want to hide it)
View controller-based status bar appearance: YES (means that you want to show it)
For more information, please see: setStatusBarHidden not working
The above link is about hiding the Status bar. If you want to show it, I think you can just try the exact opposite.

Set status bar colour for different view controllers

I have 6 view controllers. I'd like to set the status bar of my first view controller to black and then the other 5 to white. All view controllers are in a push stack.
I've tried to implement
[self setNeedsStatusBarAppearanceUpdate]
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
That does not seem to work. I've also tried playing with the apps plist properties. Any ideas?
If you want to change Background colour of status bar then that's possible.
you have to change UIWindow 's background colour to your preferred colour. try following
e.g.
[[UIApplication sharedApplication].delegate window].backgroundColor = [UIColor orangeColor];
and if you want to change text colour then just try
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
You have missed this settings in Plist
View controller-based status bar appearance to YES
Do the following things.
View controller-based status bar appearance = NO in plist.
The ViewController that you want to make white in ViewwillApper add
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
The ViewController that you want to make Black in ViewwillApper add
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];

Status bar when hidden navigation bar in iOS 7

I build app using UINavigationController is root view, i have issue hide navigation bar, when i hide navigation bar self.navigationController.navigationBarHidden = YES; status bar translucent not like status bar iOS 6 version like app Apple Store
How to fix it?
PS: I use UIBarPositionTopAttached to UIStatusBar like iOS 6
1.Add this line in your viewDidLoad to get default iOS6 style..
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque];
If you need default syle in whole app means try this.
info.plist
----> Status Bar Style
--->UIStatusBarStyle to UIStatusBarStyleBlackOpaque
2.Add following method to adjust status bar height in iOS7..
- (void)viewDidAppear:(BOOL)animated
{
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
if ([[UIDevice currentDevice].systemVersion floatValue] >= 7) {
CGRect windowFrame = [UIScreen mainScreen].bounds;
windowFrame.origin.y+=20.0;
windowFrame.size.height-= 20.0;
self.view.frame = windowFrame;
[self.view layoutIfNeeded];
}
}
you can directly set status bar black opaque through plist add this key in .plist file
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackOpaque</string>
Thanks.

UIStatusBarStyle battery color is green [duplicate]

This question already has an answer here:
UIStatusBarStyleLightContent Not setting battery white?
(1 answer)
Closed 9 years ago.
Alright I have my UIStatusBarStyle set to white with this
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
and it's working BUT….. The status bar battery icon is green, how are we supposed to change that?
About the battery being green it's green only when charging the iDevice, when not charging the battery icon goes white or black according to the style of your statusbar.
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
or
If you prefer to opt out of having view controllers adjust the status bar style—and instead set the status bar style by using the UIApplicationstatusBarStyle method—add the UIViewControllerBasedStatusBarAppearance key to an app’s Info.plist file and give it the value NO.
Or
try this
Set "View controller-based status bar appearance" (UIViewControllerBasedStatusBarAppearance) to YES in your Info.plist. (YES is the default, so you can also just leave this value out of your plist.)
your class viewDidLoad method, call [self setNeedsStatusBarAppearanceUpdate].
To Implement preferredStatusBarStyle, returning the status bar style that you want for this view controller.
-(UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}

White status bar disappears when Navigation bar is visible with Tint Color in iOS 7

I have 2 UIViewControllers. In the first UIViewController, say ViewController1 , I am keeping the UINavigationBar hidden. As my app's theme is black , so I need white UIStatusBar in iOS 7 so that it doesn't become invisible in black UINavigationBar. For getting white UIStatusBar I am using this method in iOS 7.
set the UIViewControllerBasedStatusBarAppearance to YES in the plist
in viewDidLoad do a [self
setNeedsStatusBarAppearanceUpdate];
add the following method:
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
It works fine when I am in ViewController1 . But when I move to ViewController2 then if I set
self.navigationController.navigationBarHidden = NO
in my viewDidLoad method. Then the above code for white UIStatusBar doesn't work. UIStatusBar becomes black and I can't see it because I am using the following codes to customize my UINavigationBar
self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
self.navigationController.navigationBar.translucent = NO;
If I keep UINavigationBar hidden like ViewController1 then white UIStatusBar is visible again. But when UINavigationBar is visible then status bar becomes black again. That's the problem.
Can anyone help me in this context , how can I get white status bar like my ViewController1 ?
Thanks in advance.
Have you tried adding this to both view controllers
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
You are probably just missing the attribute needed on the plist: View controller-based status bar appearance to NO.
EDIT: Check #caglar comment on previous answer for a more comprehensive answer to what's needed in general.

Resources