The main view of my app is a scrollable UICollectionView embedded in a UITabBarController. I'm not using a navigation bar and when the user scrolls he sees the cells behind the status bar, because the status bar has no background.
I've used UIApplication.shared.statusBarView?.backgroundColor = .white in my AppDelegate to apply a background and to make the status bar look like desired.
This works fine, but doesn't look nice when you're presenting a UIAlertController.
The white status bar stays above the dimmed background.
Is there a better way to apply a background to the status bar or a way to keep it behind the UIAlertController background?
You can try to use a UIView with a background color at the top of your presenting UIView.
Height of status bar can come from UIApplication.shared.statusBarFrame. And update your view size when receiving UIApplication.didChangeStatusBarFrameNotification.
Related
I have a app that only have a form with a web view. When the web view scroll (it have a white background) the content slide behind the status bar, turning it transparent (only the battery indicator is visible. The rest text of the status bar was white and now is not visible).
I need the status bar to be opaque, and the content disappear behind it.
I try setting Status bar style to default, opaque style and none work. Neither putting the background color of the view.
I want to make my whole ViewController grey except I want the top area where it shows CARRIER and the current time to remain white. Is the only way just to stick a View that covers everything except that area, and set it to grey, or is there some way to set the entire background to grey and only set that one strip to white
The "top area with clock" is called a status bar. That bar is transparent and is displayed as the topmost view in a window. This means that nothing can cover the status bar.
You can show, hide and change the appearance of the status bar (changing the content from Light to Dark implies that the text colour within your status bar will be either white or black) by sending the appropriate message to the [UIApplication sharedApplication] object.
Now that you know a little bit about the status bar, I can answer your question:
In order to have a different background under the status bar than on the rest of the screen, you need to add a view with the frame [[UIApplication sharedApplication] statusBarFrame]. Then you can colour the view property of the view controller differently than the view underneath the status bar.
Set your ViewController's view's background color to gray. Then add a white subview to it matching the status bar's frame.
I've read a few questions here and searched around a bit but nothing seems to solve my problem. I have a side navigation controller of which I am sliding the status bar (using a technique outlined here: Moving status bar in iOS 7).
In any event, when I hide the status bar to begin the slide (as soon as I tell the view to hide the status bar and add a fake one), the entire view moves up behind my faux status bar. Is there any way to move the view down so that the faux status bar appears directly above the view?
may be some autolayout issueAs there is no status bar , the view frame went to frame.origin.y=0. Try setting the frame to origin.y=20 before you hide the status bar.
If you are adding fake status bar as subview to mainView. set frame of fake status bar view to (origin.y=-20)
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.
I have stumbled across a weird problem when implementing a view container which is connected with child view controllers.
The hierarchy is the following:
I have a UISplitViewController and in the MasterViewController I added a view container which is connected to a UIViewController which is embedded in a UINavigationController.
The outcome is the following:
The ChildViewController leaves a white space at the top which seems to be exactly as high as the status bar. How can I avoid that the status bar frame is shown in the child view controller?
I tried to set wantsFullScreenLayout for the ChildViewController and for its UINavigationController but it doesn't change anything.
I also tried to set the y offsets of the views to -20.0 points but that ends up in another problem.
Only when I set status bar hidden for the application it is not shown for the ChildViewController but that in turn also hides the status bar at the top of the UISplitViewController.
Would be glad for some hints.
Basically it looks like the top gap is the status bar. The statusbar at the moment is 'light' colored which is why it's not showing on top of the white background. Try changing the background color of the view controller to black or use one of the appearance callbacks to change the status bar to a darker color.