How to manage the gap between two views in auto layout

百般思念 提交于 2019-11-29 17:58:01

Take a UIView with alpha 0 and clear color and use it instead of the gap and use aspect ratio to the view used for gap and top and bottom or left and right whatever your situation to the views between whom you want to make the gap dynamic. And also you need to add some more alignment constraints to the gapView but it will work. I could not found any other method to do this easily so i have used this method everywhere in all projects and all working fine. I think UIView with clear color and alpha 0 will not effect the screen or performance in any way. We can use this.

Here is an example like if you have two text fields vertically and you want to increase the gap between them dynamically then take a view between then with the exact same width of text field and add those constraints.

1) Top of GapView to upper text field.

2) Bottom of GapView to below text field.

3) Equal width to any text field or leading and trailing to superview or main view.

4) Proportional Height to main view(you can add this constraint by adding equal height from subview to any of superview and then by changing the multiplier);

And your GapView will increase and decrease accordingly.

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