How to make statusbar not transparent (storyboard) - ios

I've got a pretty straightforward question and somehow I didn't find an answer on this site yet.
I've got a view with a background a yellow color. I'm displaying content in the view and in order for the statusbar to not conflict with the content, I want the background to be non-transparent and preferably set to specific color.
How do I do this with storyboards?

The only way I see is to add a 20 height view aligned to the top of the view to act as a status bar background.
20 is the current size of the status bar but it's better if u get it programatically.
[UIApplication sharedApplication].statusBarFrame.size.height

Related

Set navigationbar size according to background image

I have set an backgroundImage for my navigationbar. This works fine. But I would like to have the navigationbar height to be adjusted to the background image. At the moment the width of the background images is also not set according to the screen size.
I tried setting the height of the navigationbar like described here. This shows a bigger navigationbar for like a second but then it shrinks to its default size again.
Does anyone know how to achieve what I want? Here is an example of what I want to achieve: image
Apple Documentation:
It is permissible to customize the appearance of the navigation bar
using the methods and properties of the UINavigationBar class but you
must never change its frame, bounds, or alpha values or modify its
view hierarchy directly.
To achieve the effect seen in the image you tagged, they are most likely using a collection view to layout their data and that image is part of the collection view's header. They made the navigation bar background color clear, but the image is definitely not part of the navigation bar itself.
Apple recommends to never change the frame of a navigation bar manually because it messes with the layout code of its subviews and animation methods.
You could either subclass the navigation bar and attempt to create something similar, or go the easier route and make the navigation bar clear (UIColor(white: 0, alpha: 1) not .clear otherwise it might show up incorrectly) and have an underlying view display the image (e.x. a collection view whos header extends to the top of the view controller).
This will allow you to adjust the image height and width freely without subclassing the navigation bar, and creating potential bugs.
You can make custom NavigationBar class.
It can be help you
https://developer.apple.com/library/archive/samplecode/NavBar/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007418-Intro-DontLinkElementID_2

Clear background for status bar in iOS

How can I set the colour of the status bar to be clear. No matter what I do, it is white with some alpha.
I do not want it to disappear and I want the text to be black.
In the picture it might look like nag bar and status bar are grey but actually both are white with some blur affect or nag bar has blur affect and status bar is clear.
Here is what I get despite the clear status bar background colour
The status bar has no background since iOS 7. In other words, it's clear by default.
If you see it white, it means the underlying view is white, and you need to change that.
I was having the same problem. It ended up that my view was constrained to the top layout guide when instead it should have been constrained to the superview. Even though the view is constrained to different points it will look the same in interface builder (in my case, I think this is because I was instantiating the viewcontroller to my navigation controller in code and not displaying the navbar). See the image below.
Click on the constraints for the imageview in the view above and the difference in constraints can be seen in the size inspector.
Constraining to the superview will look like this:
This results in the simulator displaying the view like this:
Notice how the status bar is clear and overlaid on top of the imageview.
Constraining to the top layout guide will look like this:
This results in the simulator displaying the view like this:
Notice how the status bar appears white and how the imageview seems constrained to the status bar (the status bar is white text on a white background fyi).
So, in order to fix this problem, you need to change the constraint of the image view to be constrained to the superview.
You change this by selecting the constraint in this list:
Once you have the constraint selected you can change what the constraint is attached to over here:

Applying bar metrics on a standalone UINavigationBar

My app has a view controller that due to the fact it plays its own custom transition animations, provides its own standalone UINavigationBar view at the top (As opposed to using a UINavigationController).
When using an iPhone, and when rotating the device, I would like the UINavigationBar to automatically apply the landscape UIBarMetrics properties (eg, change height, change the background image, resize the buttons etc), but by default, it does not. This is a problem on iOS 7, since even if I manually change the height of the UINavigationBar, the UIBarButtonItem elements don't change their vertical positions.
Is there a way to manually 'tell' the UINavigationBar to apply specific bar metric properties to itself? Or is that actually an implementation inside UINavigationController, and not UINavigationBar?
After various testing and trial and error after asking this question, I eventually worked out a solution that fixed all of my issues, so I'll post it here under the solution I'd previously accepted.
When my app is displayed in landscape on an iPhone, I wanted the UINavigationBar at the top to shrink to the standardly accepted 32 points high, as is the case with any apps that use the UINavigationController class. However, as I am not using a UINavigationController for this particular view (for varying reasons of feasibility), I needed to implement this manually.
To account for the new transparent status bar in iOS 7, I adjusted the origin and size of the UINavigationBar so it encompassed both the bounds of the status bar, and the normal UINavigationBar region (ie, so the UINavigationBar frame origin was {0,0}, and the height was 52 points.)
Unfortunately, this happened:
While the bar itself is rendering at the proper position and height, all of the content in the bar, including the title and buttons are not positioned properly, being much too high, almost touching the status bar content.
It was pretty obvious what was happening. The navigation bar content is being vertically aligned to its own middle, completely disregarding the presence of the status bar content.
When I tested the same orientations with a normal UINavigationController, this was not the case, and the title and buttons in the UINavigationBar from the UINavigationController worked absolutely fine. Apple had done SOMETHING in there that wasn't part of the normal UINavigationBar implementation.
Going on this, I picked apart the view layout hierarchy of a UINavigationControllerto see what was happening to the UINavigationBar in there (Mainly calling a lot of NSLog() statements that would dump the subviews of the navigation bar.)
This is what I discovered:
From the looks of it, Apple have employed a relatively sneaky hack to achieve this effect. It turns out the actual UINavigationBar is actually placed right below the status bar (ie at point {0,20}) and only has a height of 32 points. Then, what happens is a private subview inside the UINavigationBar in charge of rendering the background is extended upwards, outside of the bounds of the navigation bar to encompass the region behind the status bar (ie, its origin is {0, -20}, and its height is 52 points, local to the navigation bar's subview coordinate space).
So by doing that, not only does the content vertically align properly, but the translucent effect still extends behind the status bar.
Anyway, after I discovered this, it was pretty straightforward to write a solution. All I needed to do was reposition and resize the UINavigationBar back to how I had it iOS 6 (ie, 20 points down, and only 32 points high), and then implement a UINavigationBar subclass that override the layoutSubviews method, grabbed the internal background view (Doing a quick subview check for a view with a class name that matched "Background"), and then manually extended it.
The bar metrics properties you can set on a UINavigation bar are things like background image and the title vertical position. Heigh and width need to be set from within your view controller.
If you need to manually tell the navigation bar to change it's size when the orientation changes you can implement the method - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration1 in your view controller and change the size there.
Another option you can use is to use autolayout to specify that the width of your navigation bar is pinned to the left and right sides of its superview and let it figure out how wide it should be. For example
UINavigationBar *bar = [[UINavigationBar alloc] init];
bar.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:bar];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|[bar]|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(bar)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|[bar(44)]|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(bar)]];

Any quick solution to make a view appear behind the status bar in iOS 7?

I'm porting my app from iOS 6 to IOS 7 (there will eventually be a complete GUI redesign for iOS 7 but in the meanwhile just getting the existing GUI to display properly on iOS 7 is the goal.
I had the issue where the status bar was overlapping my GUI and so have shifted the Y origin of the view controller's view down by 20.
However my app contains a pulldown which when retracted is overlapping with the status bar. In the screenshot the red is a button which is present in the pulldown view. The grey bar is the top of the main view behind which a portion of pulldown is hiding when retracted.
I implemented the pull down as a fixed size child subview of the main view and when retracted its Y origin is a negative number thus it is effectively still displayed but off the top of the screen. When the user pulls it down I just animate the increase in the Y origin until eventually the origin is 0.
Is there some way I can make the pull down view appear beneath the status bar or some other quick solution?
Note of course I can't simply toggle the pulldown's alpha to display/hide it as it pullsdown obviously thus its appearance/disappearance is not a discreen action. I could maybe attempt to make the portion of it that is on top of the status bar invisible but as its something that is moving that seems like its going to be complicated. Is there any simple solution?
Thanks
Add another view, with a fixed position, under the status bar (with the same color of your grey bar), 20px tall and same width of the status bar, but with a z-index higher than the retracting view. This view will cover the retracting view (but not the status bar) acting as a "background" for the status bar itself. Obviously you have to adjust the Y position of the retracting view to make it tappable by the user (but under the status bar)
iOS 7 by default lets views take up the fullscreen, including the status bar. This is controlled using the UIRectEdgeAll property.
If you want the old style view, set UIRectEdgeNone for self.edgesForExtendedLayout
in viewDidLoad:
self.edgesForExtendedLayout = UIRectEdgeNone;

UIViewController: Preferred way to handle Content scrolling behind transparent status bar

With iOS 7 we get the fancy transparent/blurry status and navigation bars.
I saw many posts here on SO talking about the content being overlapped by the status bar.
I understand why this is happening and it's ok in my case.
Now, I was wondering since I don't have navigation bars in my app:
How shall I handle any content being scrolled behind the transparent status bar.
(Note: By scrolling I mean real scrolling through content)
In my opinion it doesn't look nice if the status bar simply overlaps the content.
Is there an easy way to make it look "nicer"? Or do I have to play with offsets and manual blur to achieve a better look?
If I have understood the question, could you not place the background image to cover the entire screen and offset the scroll view y position by 20px (the height of the status bar).
Therefore you still get the nice effect of the transparent status bar but no content ever going under the bar itself.

Resources