Cupcake icon indicating copy to clipboard operation
Cupcake copied to clipboard

HStack Fill equally

Open OuSS-90 opened this issue 6 years ago • 1 comments

Hello, I have two label inside HStack and i want to make them fill equally (each label = 50% width of content) How can i do that ? I tried align(.fill) but didn't work

OuSS-90 avatar Feb 20 '18 14:02 OuSS-90

By default HStack(or VStack) only supports items with intrinsic content size or fixed size. With one exception, align(.fill), which will stretch the cross axis to match the size of Stack (aka. vertical axis for HStack, horizontal axis for VStack).

If you want a proportional size for your items on main axis, you have to combine with constraints. view1.makeCons { $0.width.equal(view2).multiply(0.3) }

In your case, simply use: label1.makeCons { $0.width.equal(label2) }

nerdycat avatar Feb 26 '18 03:02 nerdycat