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];
Related
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.
Any ViewController added to the NavigationController directly has a gray status bar which matches the color of the NavigationBar.
But Whenever I display a Modal, the status bar is white, which doesn't match the NavigationBar I have placed in there?
I have seen tons of answers on here, most of them don't work, and the ones that do don't seem to be good solutions. For instance I don't want to wrap every single modal inside of a UINavigationController.
I tried the following which was also recommended which completely gets rid of my status bar, and that's not what I want.
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
So what's the magical solution here?
Status bar color depends on the top view color of the view(View that is connected to the status bar).
If navigation bar is connected to the status bar then status bar takes the navigation bar.
if navigation bar is hidden then the top view that is connected to the status bar. that view color will be taken by the status bar.
So if navigation bar is not there then you should change the color of the view that is connected to the status bar.
Hope this help.
Implement this code when displaying the modal view to force the application to change style.
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
Probably best in the Modals UIViewController
-(void)viewWillAppear:(BOOL)animated
In the applications plist you also need to set
View controller-based status bar appearance: NO
Not sure if this is a good solution. How about trying something like:-
-(void)displayModal{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,320, 20)];
view.backgroundColor=[UIColor grayColor];
[delegate.window.rootViewController.view addSubview:view];
[delegate.window makeKeyAndVisible];
}
-(void)dismissModal{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,320, 20)];
view.backgroundColor=[UIColor whiteColor];
[delegate.window.rootViewController.view addSubview:view];
[delegate.window makeKeyAndVisible];
}
Try setting the background color on the navigation controller's view:
let navController = UINavigationController(rootViewController: yourController)
navController.view.backgroundColor = UIColor.blue
// If you also want to set the navigation bar background color:
navController.navigationBar.backgroundColor = UIColor.blue
How can I hide the navigation bar by not hiding the status bar in my app? When I try [self.navigationController.navigationBar setHidden:YES]; it also hides the status bar. I need to show the status bar like this:
I need to first hide a visible navigation bar, make the status bar still visible and I also have a view that I need to move below the status bar, but the view is being positioned like the navigation bar is still there when I set the frame's position to 0,0.
I setup my statusbar as:
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Add this to your code where you want to hide the navigation bar
[self.navigationController.navigationBar setHidden:YES];
If you want to hide navigation bar but show status bar, you should set Top Space to Top Layout Guide as 0 instead of -44. and then
Hide navigation bar in viewWillAppear instead of viewDidLoad: [self.navigationController setNavigationBarHidden:YES animated:YES]
I start to set top space as -44, then call method [[UIApplication sharedApplication] setStatusBarHidden:NO], it doesn't work.
In my case, the status bar text and symbols were not shown because they had the same color as the background (black). I solved the problem by changing the background color:
[self.navigationController.navigationBar.superview setBackgroundColor:UIColor.whiteColor];
I have light top bar colors in my app, because the navigation bar is dark brown:
When I tap search (Keresés here), the following code sets the top bar color to dark content:
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
So it looks like this:
But when I type something into the field, then scroll the results list, the keyboard dismisses and the top bar is reverted to white. How can I prevent this?
In iOS 7, the status bar style is, by default, determined by the return value of the UIViewController method -preferredStatusBarStyle. The default implementation of this method returns UIStatusBarStyleDefault.
Setting the info.plist key UIViewControllerBasedStatusBarAppearance to the value of NO returns to the pre-iOS 7 style of taking the status bar appearance from the shared UIApplication object
To fix this you have two options:
1) Implement the -preferredStatusBarStyle method in all your view controllers that want the status bar style to be non-default
2) Add the key "View controller-based status bar appearance" (UIViewControllerBasedStatusBarAppearance) to your info.plist file and set its value to NO
The solution is in this comment: https://stackoverflow.com/a/19513714/511878
Summary: UINavigationController does not forward -preferredStatusBarStyle to it's children.
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