4

I've recently been encountering a difference in the regular / regular sizing class among different iPads, here's my related question Regular / Regular position sizing constraints for all iPads, including iPad pro?

Although I can use a multiplier and a constant to provide a margin, which is based on the device height, I can't now apply this approach to the spacing between views. Obviously, because I'm create a constraint between two views and can't therefore add the device height aka superview into the constraint.

I'm faced with having to add a clear / blank spacing view which is proportional height to the superview and pin my two views above and below it.

I'm looking for a different approach, is there one I'm not aware of?

Community
  • 1
  • 1
Jules
  • 7,190
  • 14
  • 93
  • 171

2 Answers2

0

I tried it this way:

In the below example I have two views. And I want spacing between them. The constriants on both views are.

view1:

  • Top space
  • Leading
  • Trailing
  • Proportional Height to superview(View1.height = 45% superview.height)

View2:

  • Leading, Trailing, Bottom, Proportional Height to Superview(View2.height = 45% superView.height)

Here I did not fix the spacing between them. So Spacing will be different on different screen sizes.

So you divide your views heights in such a way that create spaces between them automatically.

This is one way. The other way is to use priority and greater then or equal to, less then or equal to, type of constraints.

Result on different devices:

IPHONE

enter image description here

IPAD 2 (50 % Zoom level)

enter image description here

IPAD PRO (50 % Zoom level)

enter image description here

Irfan
  • 4,750
  • 1
  • 27
  • 31
  • Thanks, can you explain the relation approach with items required in the constraint please? Both of my views are draw and replace images, so the aspect ratio is important, I believe the first approach would lose this ratio. – Jules Dec 12 '15 at 07:27
  • In this way we can set a vertical spacing between these two views. Edit the constraint and change = to >=. – Irfan Dec 12 '15 at 07:35
  • Despite reading / watching tutorials I'm still confused about relations. I mean with => why isn't their a max value. I don't get how the constraint would increase. – Jules Dec 12 '15 at 07:38
0

Doh, all I'd need to do is follow the same approach as the other answer, and treat the top of the lower view as the top view. Then if I had problem with the top view views and lower view crashing into each other, then I could add a constraint with a priority.

enter image description here

Jules
  • 7,190
  • 14
  • 93
  • 171