Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Set Equal Width or Equal Height in StackView?

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

Labels layout detail

Labels layout detail visually

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

like image 733
Stanley Avatar asked Oct 06 '16 02:10

Stanley


People also ask

How do I change the stack view height?

'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).

How do I increase the width of a stack view?

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.

What are stack views?

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.


1 Answers

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:

  • Take your Labels inside one View(Content View).
  • Set the width of Right label equal to the Left Label, set the multiplier to 0.30.

Storyboard

like image 55
Bista Avatar answered Sep 17 '22 04:09

Bista