Status bar in single view hide/ style - ios

in my app I've multiple views . I need to hide the status bar for one view ( this vC2 is in order navigationC -> VC ->push to vC2) . it works firstly by setting
View controller-based status bar appearance = NO in plist
and then use
[UIApplication sharedApplication].statusBarHidden = YES; in the viewWillAppear
and [UIApplication sharedApplication].statusBarHidden = NO; in viewWillDisappear
to reback the status bar.
Then , I want to set the status bar with light colour style for another single view (VC3) in the same app. only one way works with me is
by setting View controller-based status bar appearance = YES and use
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
in the VC3.m
my problem is around View controller-based status bar appearance which used with NO value for hiding status bar and used with YES value for light style of status bar
Can I combine the the hiding / and style status bar in my app?
My target is iOS7

YOu can by using this function in viewController:
- (BOOL)prefersStatusBarHidden {
return YES;
}
The plist boolean has to be YES and you can add something more:
Try
[self setNeedsStatusBarAppearanceUpdate]
And in case you have view controllers as childs of other viewControllers, the last child is the one that should decide
If the VC is child of another VC (this on the first level VC that you subclass, not need if you are using a navigation without subclassing)
- (UIViewController *)childViewControllerForStatusBarHidden {
return _myChildViewController;
}

Related

Setting statusBar style does not work Objective-C

I am trying to change my statusbar style (the color of status bar text, more specifically) depending on which viewController is active through this:
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
But that does not work. Rather, it makes the whole navigationBar black (instead of just the statusbar). Neither does the following:
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
But this only seems to work when the viewController is not embedded in a navController (when I hide the navBar, it works!). My viewController hierarchy is the following:
tabBarController -> navigationControllers -> viewController
Also: Setting 'View controller-based status bar appearance' to YES & NO does not make a difference.
I am glad for any help!
You can try following.
keep this to your ViewController
-(UIStatusBarStyle)preferredStatusBarStyle{
// Add If/else conditions based on which style required on which condition
return UIStatusBarStyleLightContent;
}
Call this code when you want to change the status bar style..
[self preferredStatusBarStyle];
[self setNeedsStatusBarAppearanceUpdate];

Unable to remove top bar for iOS 10

I have tried almost all the answers but I can't get it to work.
What I have tried so far.
Target/Generar/Deployment Info: Status Bar Style -> Light, Hide status bar checked.
[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
- (BOOL)prefersStatusBarHidden {
return YES;
}
and
Status bar is initially hidden = YES
View controller-based status bar appearance = NO
What else can I try?
The problem is that the view controller in which you are saying this:
- (BOOL)prefersStatusBarHidden {
return YES;
}
...is not the view controller that is consulted with regard to the status bar's visibility. That view controller is the top-level view controller: the ultimate root view controller. Your view controller is just a child of that view controller, so your prefersStatusBarHidden is never called.

Hide ios status bar when "View controller-based status bar appearance"=YES

I need to change status bar style depending on the view controller so in my plist-file "View controller-based status bar appearance" is set to YES.
And I need to sometimes hide the status bar!
I'm trying to use setStatusBarHidden but it seems to work only if "View controller-based status bar appearance" is set to NO ...
So is there a way to hide the status bar ?
First, declare a variable to indicate hidden or not:
#interface ExampleViewController
{
BOOL statusBarHidden;
}
Second, override UIViewController's method which depends the variable:
- (BOOL)prefersStatusBarHidden {
return statusBarHidden;
}
Finally, when you need to hide status bar, do:
statusBarHidden = YES;
[self setNeedsStatusBarAppearanceUpdate];
When you need to display status bar again, do:
statusBarHidden = NO;
[self setNeedsStatusBarAppearanceUpdate];

How to retrieve view controller that currently controls status bar appearance?

Is there a way to retrieve, from anywhere in an app, the view controller that is currently controlling the status bar appearance?
Dont think you can retrieve in a controller that way, but you can change the style of the status bar.
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;
}

Status Bar iOS7

I have two views and I need one to be able to show a white status bar and the other to show no status bar. I have successfully made it show NO status bar but have not been able to have the Main view have a White status bar. I have to use View controller-based status bar appearance = YES because otherwise When i go back from the "no status bar view" it makes it makes the whole app have no status bar. Why won't the status bar be white!?!
Current Code for dismising status bar:
-(BOOL)prefersStatusBarHidden
{
return YES;
}
-(void)ViewDidLoad {
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)])
{
[self prefersStatusBarHidden];
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
}
else
{
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
}
Current Code for trying to make the status bar white:
- (void)viewDidLoad {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
[self setNeedsStatusBarAppearanceUpdate];
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
You shouldn't be calling prefersStatusBarHidden in your first block, you should be implementing it to return true.
Make sure you have View controller based status bar appearance (UIViewControllerBasedStatusBarAppearance) set to yes in your Info.plist file.
What this all means is that in the VC where you want the status bar hidden you need to put:
-(BOOL)prefersStatusBarHidden
{
return true;
}
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleDefault;
}
In the other VC, put:
-(BOOL)prefersStatusBarHidden
{
return false;
}
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
Just checked it out and it all seems to work as expected. Note that in iOS 7, UIStatusBarStyle only controls the color of the text in the status bar, the background color is determined by the navigation bar itself.
Why won't the status bar be white!?!
Well, simply because it is transparent. The "background colour" of the status bar is now (post ios7) the colour of the view/window behind the status bar.
but have not been able to have the Main view have a White status bar
The solution I commonly use, is to force the navigationController's navigationBar to render below the status bar rather than behind it. This way, the navigationBar's colour/background image doesn't extend under the status bar and the status bar's "background colour" is now the colour of the window.
To force the navigation bar to start below the status bar, you set its clipsToBounds property to YES.
_navigationController.navigationBar.clipsToBounds = YES;
To set the background colour of the window,
self.window.backgroundColor = [UIColor whiteColor];
Ref: Ironically, our "solution" was someone else's "bug" :)

Resources