Is it necessary to use autolayout to use stackview

我的梦境 提交于 2019-12-24 02:16:39

问题


Is it necessary to compulsory use autolayout to just use of stackview suppose i have made whole project without autolayout, now for particular screen i have to use the Stackview to equally divide the number of label inside the view. is there is any solution for that..

PROBLEM

actually i have to customize one of my old project done without autolayout, Now i have to just modify one screen which does not require any constraint but just stackview like uitablecell with 8 label in each cell equally divided.

I know we can do it by just calculating frame run time but is there is any other way to do it.


回答1:


Yes, it is necessary to position the stack view itself using Auto Layout

From the Apple Documentation:

Although a stack view allows you to layout its contents without using Auto Layout directly, you still need to use Auto Layout to position the stack view, itself




回答2:


If you set the stack view's translatesAutoresizingMaskIntoConstraints property to true, then you can set the stack view's frame and autoresizingMask to control the size and position of the stack view. Auto layout will automatically turn your settings into constraints for you.

The arranged subviews of the stack view must not have translatesAutoresizingMaskIntoConstraints set to true.




回答3:


The stack view uses Auto Layout to position and size its arranged views. Although a stack view allows you to layout its contents without using Auto Layout directly, you still need to use Auto Layout to position the stack view, itself. In general, this means pinning at least two, adjacent edges of the stack view to define its position. Without additional constraints, the system calculates the size of the stack view based on its contents.

https://developer.apple.com/documentation/uikit/uistackview



来源:https://stackoverflow.com/questions/49291518/is-it-necessary-to-use-autolayout-to-use-stackview

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