Reputation: 34780
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:
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:
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)?
Upvotes: 10
Views: 9566
Reputation: 1390
If you're using Safe Area Layout Guides you can do this completely in Interface Builder.
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.
Upvotes: 6
Reputation: 424
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.
Upvotes: 2
Reputation: 34780
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.
Upvotes: 3