简体   繁体   中英

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

标签布局细节

直观地标记布局细节

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

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 .

故事板

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM