Replace status bar with own view - ios

I would like to replace the UIStatusBar in my app with my own view.
I'm assuming that I need to hide the status bar - is this right?
The problem with hiding the status bar is that the navigation bar moves up to occupy it's original position. How can I add my view and move everything back down 20 px?
Assuming that I don't have to remove the status bar, but instead can just cover it with my view, I then have the problem of the background color. This changes between views, so I would need to mask out the existing status bar text - how do I do this?
Thanks for your help.

Your approach is correct with a little tweak with self.view's frame.
Add below method to your viewController,
-(void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
self.view.frame =CGRectMake(0, 20, 320, [UIScreen mainScreen].bounds.size.height);
}
Above method moves your view by 20 pixels down.

The first step would be to hide the status bar. In iOS 7, you can do this by adding the prefersStatusBarHidden function, like so:
- (BOOL)prefersStatusBarHidden {
return YES;
}
This will hide the status bar.
To fix the movement issue you mentioned, you need to set the status bar style for the viewController to none (in the interface editor).
Start off by selecting the View Controller in the left side panel:
Head over to the Attributes Inspector on the right side of Xcode, and set Status Bar to none:
That's it, now you can add your own view at the top of the screen with your own content :)

To hide the status bar completely in iOS7, set "View controller-based status bar appearance" to NO in Info.plist, and [[UIApplication sharedApplication] setStatusBarHidden:YES]; in application:didFinishLaunchingWithOptions

I think you are using autolayout. So for doing that just place all of your views inside another view and in delta y put 20px for ios6/7. and don't forget to follow Audun Kjelstrup's step. Hope it will solve your problem.

Related

Show status bar with animation causes view to move up 20px so its under the status bar

I have a UIViewController that shows and hides the status bar. Hiding the status bar works no problem, however when I show the status bar using:
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
Causes the contents of the View to move up 20px so it ends up under the status bar. I dont know what else I can provide but this description, all that happens is when I hide the status bar, there is 20px of white space at the top where the status bar would be (this is what I want) but when I show the status bar the view moves up under the status bar (this is not what I want). The desire is to show and hide the status bar without effecting the UIViewController and its contents.
I had the same issue. I managed to fix it in the Storyboard.
The top constrain for the view that was shifting up was set to Top Layout Guide. I changed it to point to Superview.Top and the view stopped moving.
To explicitly use Superview over top layout guide, you need to use the Pin (button on bottom left corner of storyboard) and before setting up the constrain uncheck "Constrain to margins"
I solved this by removing auto-layout on this ViewController and manually set the views layout in :
-(void)viewDidLayoutSubviews
Seems to solve the issue. Cheers to #ThatGuy for pushing me in the right directions.

Setting status bar hidden is messing with my navigation bar background image size

In my app I want to change only one view controller status bat to hidden.
So in the view did load method I added this:
- (BOOL)prefersStatusBarHidden
{
return YES;
}
Thats what allot of the guides online said to do.
Now, this view controller is a table view, and I have set its nav bar background image to something custom, it looks like this before Im hiding the status bar:
And after I added the hidden method:
So you can see it cuts part of the bg image (with the green line).
my nav bar bg image size is 640 × 128 and I put it on X2 in xcode, so this should cover the whole nav bar after hiding the status bar.....isn't it?
please help,
Thanks!
The status bar is 20 pixel in hight so either you need to programmatically increase the size on the UINavigation controller hight just for that view controller of you need a smaller background image for that view controller.

I removed the status bar from my iPad app, but now there is a white bar at the bottom that is the same thickness as the status bar

It seems like the program just moved the whole view up, and didn't stretch the webView to cover the bottom.
How can I make the webView take up the whole space, now that the status bar isn't taking up any? I tried just manually making the webView bigger in the storyboard but it has no effect.
I had the same problem in an iPhone app of mine. Try this:
- (void)viewDidLayoutSubviews
{
self.webView.frame = self.view.bounds;
}
Yup, What you are doing actually by removing status bar?
By removing status bar you are freeing space for view with that much pixel as status bar occupied.
So, now your view have approx '20px' more size,so it will show that white line which
is actually your holder view on which "UIControls" are placed (not a line).
*For that you can set size of your UIControl to view OR Use autoresize option *
self.yourwebview.frame = self.view.bounds;
OR
you can set property of webview

iOS 7 - Status bar overlaps the view content

I am using status bar in my app and wanted to maintain the compatibility between ios 6 and ios 7. I wanted status bar to behave same as ios 6. I don't want status bar to overlap view controllers.
Try adding the following code in your view's viewWillAppear function:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// if this is ios7 this code will make the view appear properly below the navigation bar
if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) {
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = YES;
}
}
Try this~
if(OVER_IOS7){
self.edgesForExtendedLayout = UIRectEdgeNone;
[self.navigationController.navigationBar setTranslucent:NO]
}
Try this.
add this key into info.plist file
View controller-based status bar appearance
set value for this to:- No
In iOS 7, the status bar is transparent, and other bars—that is, navigation bars, tab bars, toolbars, search bars, and scope bars—are translucent. As a general rule, you want to make sure that content fills the area behind the bars in your app.
Most bars also draw a blur behind them, unless you provide a custom background image for the bar.
iOS 7 introduces the barPosition property for identifying bar position, which helps you specify when a custom background image should extend behind the status bar. The UIBarPositionTopAttached value means that a bar is at the top of the screen and its background extends upward into the status bar area. In contrast, the UIBarPositionTop value means that a bar is at the top of its local context—for example, at the top of a popover—and that it doesn’t provide a background for the status bar.
By default, all bar buttons are borderless. For details, see Bar Buttons.
The Status Bar
Because the status bar is transparent, the view behind it shows through. The style of the status bar refers to the appearance of its content, which includes items such as time, battery charge, and Wi-Fi signal. Use a UIStatusBarStyle constant to specify whether the status bar content should be dark (UIStatusBarStyleDefault) or light (UIStatusBarStyleLightContent):
UIStatusBarStyleDefault displays dark content. Use when light content is behind the status bar. image: ../Art/status_bar_default_iphone_2x.pngimage: ../Art/status_bar_default_ipad_2x.png
UIStatusBarStyleLightContent displays light content. Use when dark content is behind the status bar. image: ../Art/status_bar_light_iphone_2x.pngimage: ../Art/status_bar_light_ipad_2x.png
In some cases, the background image for a navigation bar or a search bar can extend up behind the status bar (for details, see Navigation Bar and Search Bar and Scope Bar). If there are no bars below the status bar, the content view should use the full height of the screen. To learn how to ensure that a view controller lays out its views properly, see Using View Controllers.
In iOS 7, you can control the style of the status bar from an individual view controller and change it while the app runs. If you prefer to opt out of this behavior and set the status bar style by using the UIApplication statusBarStyle method, add the UIViewControllerBasedStatusBarAppearance key to an app’s Info.plist file and give it the value NO.

UIView is not autoresized after I hide the UIStatusBar

I have a ViewController which need to hide the status bar sometimes. The problem is the view of the UIViewController is not autoresized after the status bar is hidden. (Actually I have another application use the exactly the same View Controller. Which has no problem at all). Can anybody advise which could be the cause of the problem? Thanks
Please refer to my screen shots. The first one is the view before I hide the status bar and the navigation bar. The second one is after I hide the status bar and navigation bar. You can see that the there is obvious black area which previously occupied by status bar.
Seems wantsFullScreenLayout of your view controller isn't set to YES.
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
[self setWantsFullScreenLayout:YES];
Try this in your viewDidLoad.
Additionally to full screen layout I think the bar style must be traslucent.

Resources