how to put constraints on views in interface builder to satisfy all iphone Screen in Xcode 8

北城余情 提交于 2019-12-02 13:04:35

You dont apply constraints for each device anymore. You apply auto layout constraints per size class.

If you are aware each and every iOS devices falls under one of the size class in each orientation. If you aren't aware of size class do read about it.

As to answer your question, 1. You will add constraints which are common across all the size classes to any x any.

2.you can always add constraints specific to size class (What I mean is you can add constraints one size class while uninstall it in other size class if you dont want it)

3.you can select any of the constraint and provide it constant values, multipliers specific to size class (e.g.: you can set the height constraint constant to 50 in CxC while you can set it to 150 in (R x R) without adding a new constraint.

By setting multipliers to correct value you can achieve this. I have tried non-programmatically and only in Xcode 8 :

  • select one of the new view and hold ctrl & drag to the top most external view(or parent view) cause that changes with respect to different screen sizes.
  • then hold shift and select multiple option as : 1)equal width & equal height, 2)center horizontally in container, 3) center vertically in container. As soon as this is done you will see yellow lines (around your new view) which tell about unsatisfied constraints.
  • then select each constraints line(yellow coloured)or else select different constraints shown in view controller scene column and modify the multiplier until the yellow coloured line becomes blue i.e. until it satisfies the position where new view is needed to be in top most view or parent view.

screenshot showing multiplier for setting in Interface builder

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