5

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.

Jaydeep Vyas
  • 4,411
  • 1
  • 18
  • 44
  • You had used Autoresize ? or added anchors programmatically ? if you gad used Autoresizing you explicitly don't require autoLayout for StackView can you tell what exactly issue you are facing – iOS Geek Mar 15 '18 at 04:27
  • 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 uitable cell with 8 label in each cell equally divided – Jaydeep Vyas Mar 15 '18 at 04:33

3 Answers3

2

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

Daniel Hall
  • 13,457
  • 4
  • 41
  • 37
  • is there is any alternate way to doing that without autolayout – Jaydeep Vyas Mar 15 '18 at 04:31
  • Unfortunately, once you use auto layout constraints inside a view (which stack views do, although they generate them automatically), you must have auto layout constraints that also position that view itself. The constraint solver needs to be able to figure out where everything ends up relative to the outermost view in a view controller. So I'm not aware of any way to use a stack view without also using auto layout – Daniel Hall Mar 15 '18 at 04:38
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.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
0

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

ThananutK
  • 71
  • 7