Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stackview with right aligned label needs padding

I created the following layout:

enter image description here

The label on the right side, is included in a stackview, but is "clinging" to the right side of the screen when launching the app. I want to achieve some spacing, but don't know how to achieve it.

The expected output would look like this: enter image description here

like image 935
sesc360 Avatar asked Mar 15 '26 05:03

sesc360


1 Answers

When isLayoutMarginsRelativeArrangement property is true, the stack view will layout its arranged views relative to its layout margins. So here,

stackView.layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 20)
stackView.isLayoutMarginsRelativeArrangement = true

The above will add 20 pixels width of padding to the right edge of the stackview. This can also be done via the storyboard.

like image 127
Michael Long Avatar answered Mar 18 '26 01:03

Michael Long