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)?
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With