Regular / Regular spacing between views for all iPads and iPad Pro?

半世苍凉 提交于 2019-12-22 08:58:46

问题


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?


回答1:


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

IPAD 2 (50 % Zoom level)

IPAD PRO (50 % Zoom level)




回答2:


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.



来源:https://stackoverflow.com/questions/34225308/regular-regular-spacing-between-views-for-all-ipads-and-ipad-pro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!