Is it possible to have the status bar hidden in just one scene in the Storyboard?
For example:
I want it hidden in "ViewController A", but when moving via a segue to "ViewController B" (eg, a Navigation Controller) the status bar will be shown.
I gather you can disable it throughout the app, but how do you do it for just one ViewController?
The suggestion from below does work, however when switching to the Navigation Controller it seems to cause the nav bar to be drawn in the wrong location.
How about
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[super viewWillDisappear:animated];
}
Just put the code on your ViewController.m (in iOS7, Xcode 5)
- (BOOL) prefersStatusBarHidden {
return YES;
}
My solution: In the storyboard, select your Scene and set Status Bar: None in the Attributes Inspector.
For Swift 4:
override var prefersStatusBarHidden: Bool {
return true
}
Related
I want to hide the status bar for specific view controllers, not for all.
then I tried this,
[[UIApplication sharedApplication] setStatusBarHidden:YES]; in the `.AppDelegate.m` inside the `didfinishlaunchwithoption` but it didn't work. and also it is deprecated.
then I tried in my viewcontroller
- (BOOL) prefersStatusBarHidden{
return YES;
}
this also didn't work. anyone can help me with this.thnak you
I don't want to use any deprecated methods here
Go to info.plist and add two attributes if not present. set "Status bar is initially hidden" to "YES" and set "UIViewControllerBasedStatusBarAppearance" to "YES". This will hide status bar for your app.
-(BOOL)prefersStatusBarHidden
{
return YES;
}
and call this method where you want,For example from viewDidLoad
[self prefersStatusBarHidden];
I want to hide the status bar for specific view controllers, not for all.
Only the top-level view controller gets to say whether the status bar is hidden. Your prefersStatusBarHidden is not consulted because your view controller is not the top-level view controller — it has some kind of parent view controller which is in charge of the status bar.
Try the code below in your view controller.
Try the following method without deprication warnings:
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
}
- (void)viewWillDisappear:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
[super viewWillDisappear:animated];
}
Update for iOS 9
Add the following code in your viewController for hiding status bar.
- (BOOL) prefersStatusBarHidden {
return YES;
}
Try below code in your view controller.
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[super viewWillDisappear:animated];
}
Add below code to your view controller..
- (BOOL)prefersStatusBarHidden {
return NO;
}
If you change the return value for this method, call the setNeedsStatusBarAppearanceUpdate method.
For childViewController, To specify that a child view controller should control preferred status bar hidden/unhidden state, implement the childViewControllerForStatusBarHidden method.
I have an application with 2 viewcontrollers, ViewController and NextViewController. ViewController does not have a navigation bar and has a white status bar. NextViewController does have a navigation bar and has a black (default) status bar. I have encountered a bug when swiping back to ViewController from NextViewController and cancelling the swipe where the navigation bar on NextViewController will disappear. The storyboard simply has the two views with a button and an action segue. The bug does not always happen, but often enough to be a problem. The bug has to do with the method - (UIStatusBarStyle) preferredStatusBarStyle, as everything works fine when I remove the methods.
Can I somehow stop this bug from happening while still having a white status bar on my ViewController and having the swipe enabled or am I forced to remove either functionality?
ViewController
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setNeedsStatusBarAppearanceUpdate];
}
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
NextViewController
#implementation NextViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setNeedsStatusBarAppearanceUpdate];
}
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleDefault;
}
Other possibly relevant info: Experiencing the issue on an iPhone 5s with iOS 8, but it also happens on the simulator with iOS 9. View controller-based status bar appearance is set to the default, YES.
Status bar style depends on - preferredStatusBarStyle of the view controller if the navigation bar is hidden, otherwise of the navigation controller, so the - preferredStatusBarStyle in your NextViewController is useless.
It seems that the bug is related with the status bar style of the navigation controller, you can subclass UINavigationController override the method childViewControllerForStatusBarStyle to avoid the bug.
#implementation MyNavigationController
- (UIViewController *)childViewControllerForStatusBarStyle {
return self.topViewController;
}
#end
Now the status bar style will depend on the view controller no matter whether the navaigation bar is hidden or not. And the bug would not happend.
I can hide a status bar in my app:
- (void)viewDidLoad{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[super viewDidLoad];
}
When I chose my launch image and start it first time, it's status bar over a picture. How can I hide this?
You need to add this code in your AppDelegate file, not in your Root View Controller
Or add the property Status bar is initially hidden in your plist file
Folks, in iOS 7+
please add this to your info.plist file, It will make the difference :)
UIStatusBarHidden
UIViewControllerBasedStatusBarAppearance
For iOS 11.4+ and Xcode 9.4 +
Use this code either in one or all your view controllers
override var prefersStatusBarHidden: Bool {
return true }
Add the following code to your view controller:
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
What helped me is this (changing plist file):
set Status bar is initially hidden = YES
add row: View controller-based status bar appearance = NO
Put this code to your view controller in which you hide status bar:
- (BOOL)prefersStatusBarHidden {return YES;}
In iOS 7 status bar appearance depends on UIViewController as default. To hide status bar globally, in info.plist use NO value for UIViewControllerBasedStatusBarAppearance key and use UIApplication's setStatusBarHidden method with YES BOOL value.
add this key key from dropdownlist in "info.plist" and voila you will no more see top bar that includes elements something like GSM,wifi icon etc.
It's working for me ,
Add below code into the info.plist file ,
<key>UIStatusBarHidden</key>
<false/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Hopes this is work for some one .
In info.plist
View controller-based status bar appearance NO
Status bar is initially hidden YES
In view controller.m
- (BOOL) prefersStatusBarHidden
{
return YES;
}
I am supporting iOS 5, 6, & 7. My app is iPad only. I needed to use all of the following:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
View Controller:
- (BOOL)prefersStatusBarHidden{ return YES; }
Info.plist
<key>UIStatusBarHidden</key>
<string>YES</string>
<key>UIStatusBarHidden~ipad</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<string>NO</string>
Just check the box on Targets/Summary iPad Deployment Info and you status bar will disappear.
It works on my apps.
I had the same problem, but its an easy fix! Just set
status bar is initially hidden = YES
then add an row by clicking on the plus right after the text status bar is initially hidden, then set the text to
view controller-based status bar appearance
by clicking the arrows, and set it to NO
Hope this helps!
Well the easiest way that I do it is by typing the following into the .m file.
- (BOOL) prefersStatusBarHidden
{
return YES;
}
This should work!
-(void) viewWillAppear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
A complete solution in swift, in your view controller
// you can use your own logic to determine if you need to hide status bar
// I just put a var here for now
var hideStatusBar = false
override func preferStatusBarHidden() -> Bool {
return hideStatus
}
// in other method to manually toggle status bar
func updateUI() {
hideStatusBar = true
// call this method to update status bar
prefersStatusBarHidden()
}
To hide status bar for each individual view controller programmatically, use any of the following two procedures:
Procedure 1:
[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
Procedure 2:
-(BOOL)prefersStatusBarHidden {
return YES;
}
To hide status bar for the entire application, we should follow the given below procedure:
You should add this value to plist: "View controller-based status bar appearance" and set it to "NO".
Click here to view screenshot
I have a UIViewController with a childViewController.
The childViewController either takes up the entire screen or parts of the screens, overlaying on top of the parentViewController.
When it takes up the entire screen I would like to change the UIStatusBarStyle.
In my plist, I have added View controller-based status bar appearance and set it to NO.
In the childViewController I have the following:
-(UIStatusBarStyle)preferredStatusBarStyle {
if (self.isFullScreen) {
return UIStatusBarStyleDefault;
} else {
return UIStatusBarStyleLightContent;
}
}
-(UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
return UIStatusBarAnimationFade;
}
When making the transition from half and fullscreen I call:
[self setNeedsStatusBarAppearanceUpdate];
But my UIStatusBar does not change appearance from light to dark.
A regular call to:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
works fine, however but I would like to take advantage of the fact that I can match the animation duration for the change inside an animation block.
Thank you.
You should set the UIViewControllerBasedStatusBarAppearance to YES in the plist for using -(UIStatusBarStyle)preferredStatusBarStyle method.
I can hide a status bar in my app:
- (void)viewDidLoad{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[super viewDidLoad];
}
When I chose my launch image and start it first time, it's status bar over a picture. How can I hide this?
You need to add this code in your AppDelegate file, not in your Root View Controller
Or add the property Status bar is initially hidden in your plist file
Folks, in iOS 7+
please add this to your info.plist file, It will make the difference :)
UIStatusBarHidden
UIViewControllerBasedStatusBarAppearance
For iOS 11.4+ and Xcode 9.4 +
Use this code either in one or all your view controllers
override var prefersStatusBarHidden: Bool {
return true }
Add the following code to your view controller:
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
What helped me is this (changing plist file):
set Status bar is initially hidden = YES
add row: View controller-based status bar appearance = NO
Put this code to your view controller in which you hide status bar:
- (BOOL)prefersStatusBarHidden {return YES;}
In iOS 7 status bar appearance depends on UIViewController as default. To hide status bar globally, in info.plist use NO value for UIViewControllerBasedStatusBarAppearance key and use UIApplication's setStatusBarHidden method with YES BOOL value.
add this key key from dropdownlist in "info.plist" and voila you will no more see top bar that includes elements something like GSM,wifi icon etc.
It's working for me ,
Add below code into the info.plist file ,
<key>UIStatusBarHidden</key>
<false/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Hopes this is work for some one .
In info.plist
View controller-based status bar appearance NO
Status bar is initially hidden YES
In view controller.m
- (BOOL) prefersStatusBarHidden
{
return YES;
}
I am supporting iOS 5, 6, & 7. My app is iPad only. I needed to use all of the following:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
View Controller:
- (BOOL)prefersStatusBarHidden{ return YES; }
Info.plist
<key>UIStatusBarHidden</key>
<string>YES</string>
<key>UIStatusBarHidden~ipad</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<string>NO</string>
Just check the box on Targets/Summary iPad Deployment Info and you status bar will disappear.
It works on my apps.
I had the same problem, but its an easy fix! Just set
status bar is initially hidden = YES
then add an row by clicking on the plus right after the text status bar is initially hidden, then set the text to
view controller-based status bar appearance
by clicking the arrows, and set it to NO
Hope this helps!
Well the easiest way that I do it is by typing the following into the .m file.
- (BOOL) prefersStatusBarHidden
{
return YES;
}
This should work!
-(void) viewWillAppear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
A complete solution in swift, in your view controller
// you can use your own logic to determine if you need to hide status bar
// I just put a var here for now
var hideStatusBar = false
override func preferStatusBarHidden() -> Bool {
return hideStatus
}
// in other method to manually toggle status bar
func updateUI() {
hideStatusBar = true
// call this method to update status bar
prefersStatusBarHidden()
}
To hide status bar for each individual view controller programmatically, use any of the following two procedures:
Procedure 1:
[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
Procedure 2:
-(BOOL)prefersStatusBarHidden {
return YES;
}
To hide status bar for the entire application, we should follow the given below procedure:
You should add this value to plist: "View controller-based status bar appearance" and set it to "NO".
Click here to view screenshot