0

I'm making my UI with IB. My view controller looks like below in IB. enter image description here enter image description here

I set the background colour of the view controller to yellow and the subview's to red. Then I set constraints to let the subview's 4 edges align to its superview --- the view controller's view. But what I actually saw was like below. enter image description here

I printed out the subviews of the view controller's view and found that there was an 'UILayoutGuide'(top, I guess) with a height of 20 px. Is it the reason that the red subview not aligning its top to the superview?

Here are the constraints I added to the red subview. enter image description here

Other conditions: I'm not setting status bar to hidden. But If I set status bar to hidden([UIApplication sharedApplication].statusBarHidden = YES), the red subview's layout will become correct(I mean, aligning its 4 edges to the superview's so the yellow background colour can not be seen). Like below. enter image description here

Any suggestions? Thanks.

Sabbath
  • 91
  • 3
  • 26

1 Answers1

0

Accidentally, I found the answer.

In fact I'm implementing UINavigationController. I set the default navigation bar to hidden. As the documentation says

The bottom of the status bar, if only a status bar is visible.

so there will be a 20px space at the top of the view controller's view. And, since the layout guides are readonly, I can not align the top of the red subview to its superview(my view controller's view) by setting vertical space between subview's top to top layout guide's bottom.

But, here is my workaround. I set the leading, trailing, bottom spaces between superview's to 0.0px and set subview's height equal to superview's. Now, there is no space between the top of red subview's top and its superview's even when I set the status bar to visible. enter image description here

Community
  • 1
  • 1
Sabbath
  • 91
  • 3
  • 26