10
votes

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)?

3
Does this mean you have hidden the navigationController's navigationBar?Edwin Abraham
@EdAbe yes, I've hidden the navigation bar as I have some heavily customized views that I'm using as top bar/navigation bar. But I need to reach below status bar as well.Can Poyrazoğlu
Have you set the extended layouts for the view controller to edge rectzero. For me setting the navigationbar as hidden and the extended layout to zero rect made it work.Edwin Abraham
@EdAbe nope, setting self.edgesForExtendedLayout = UIRectEdgeNone; (which I assume is the one that you were talking about) did not changes anything.Can Poyrazoğlu
work for me automaticallyAdjustsScrollViewInsets = falseober

3 Answers

6
votes

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

3
votes

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.

2
votes

On the view controller or parent view controller you must set automaticallyAdjustsScrollViewInsets to NO. The previous answer is a bit of a hack since the framework provides a property that controls this behavior.