I have six labels here, every two labels are stack in a horizontal view, and all horizontal views are stack in a vertical view, as show below
Here is what I want: I'd like to set Label1
's width 30% of Label2
regardless of each label's content
The outer stack view is set as Aligment:Fill, Distribution:Fill Equally
All inner stack view are set as Aligment:Fill, Distribution:Fill
I have set Label1
's hugging to 250, and Label2
's as default (so does the others).
And I am trying to set the width by Equal Widths in pic 2. But it is unselected
what should I do about this? Preferring doing all the work in the storyboard, but working around in code is ok too.
Solution: Just need to select both label to add the constraint, as Below Solution image
'Fill proportionally' distribution type works with intrinsic content size. So if our vertical stack(height say 600) view has 2 views, ViewA (intrinsic content height 200) and ViewB(intrinsic content height 100), the stack view will size them to ViewA(height 400) and ViewB(height 200).
Select the top-level stack view and in the Attributes inspector, click the + button next to Spacing: Choose Any Width and Compact Height, then select Add Variation. Set the Spacing to 10 in the new hC field: Build and run.
Overview. Stack views let you leverage the power of Auto Layout, creating user interfaces that can dynamically adapt to the device's orientation, screen size, and any changes in the available space. The stack view manages the layout of all the views in its arrangedSubviews property.
IMO, Stack View wont allow to give some fix frame size of the views inside it, we can somewhat control it using available properties.
Stack Views are meant for similar type content to be confined inside one view.
Option:
0.30
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With