Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend UIViewController's view without a navigation bar under status bar

My view does not have a navigation bar, but I want to display content under status bar. I've checked extend edges under top bars, under opaque bars in my view controller, the view that I want to display under status bar has 0 vertical spacing constraint to top layout guide, but still, here is what I get:

enter image description here

The status bar has 20px solid white background, which I don't want. I want my view to overlap under status bar, just like the mockup below:

enter image description here

How can I do that, without having a visible navigation bar (I still have it as my view is guaranteed to be inside a navigation controller, but it's will never be visible as I have a lot of custom designed sections including top bars)?

like image 300
Can Poyrazoğlu Avatar asked Feb 06 '15 14:02

Can Poyrazoğlu


People also ask

What can I display when I extend the status bar?

When you extend the status bar, you can display information and UI in four regions: the feedback region, the progress bar, the animation region, and the designer region. The feedback region allows you to display text and highlight the displayed text. The progress bar shows incremental progress for short-running operations such as saving a file.

How can fitssystemwindows = true help to draw under the status bar?

Coming back to the question of how fitsSystemWindows = true can help to draw under the status bar? fitsSystemWindows = true sets the padding to your view (if needed) to prevent your content from being obscured by the system status bar or navigation bar. Let’s come back to our example.

How to hide the content of the app under the navigation bar?

Hiding the bars is simply achieved by calling the hide () method. Since we want the content of the app to be visible under the bars, we also set our custom semitransparent color by setting Window’s navigationBarColor.

Can a view controller ask for a full-screen layout?

However, a view controller can ask that its view be displayed with a full-screen layout instead. In a full-screen layout, the content view is configured to underlap the navigation bar, status bar, and toolbar as appropriate.


2 Answers

If you're using Safe Area Layout Guides you can do this completely in Interface Builder.

enter image description here

Pin the view you want under the status bar to the main view using the Top Space to Container Margin constraint instead of Top Space to Safe Area constraint.

Then on the Size Inspector for the main view, uncheck Safe Area Relative Margins.

enter image description here

like image 169
NSExceptional Avatar answered Oct 04 '22 23:10

NSExceptional


After investigating tens of pages for hours, I've found an answer:

for (NSLayoutConstraint *constraint in self.view.constraints) {
    if((constraint.firstItem == self.topLayoutGuide && constraint.secondItem == self.view) ||
       (constraint.secondItem == self.topLayoutGuide && constraint.firstItem == self.view))         {
        constraint.constant = -20;
    }
}

For anyone wondering, I did not use a specific one answer, but a derived solution from this question: iOS7 - View under status bar - edgesForExtendedLayout not working.

like image 26
Can Poyrazoğlu Avatar answered Oct 04 '22 23:10

Can Poyrazoğlu