Friday, October 9, 2026
HomeiOS Developmentswift - iOS AutoLayout: I ponder set stackView's views View Precedence. what's...

swift – iOS AutoLayout: I ponder set stackView’s views View Precedence. what’s completely different by setting?

[ad_1]

Good day 🙂 I research UIStackView views precedence.

img1

this image is my present state of affairs.
I put greenBtn, redBtn, yellowBtn in stackView.

I additionally set every button dimension.

GreenBtn width = 100, top = 100.

RedBtn width = 200, top = 300.

YellowBtn width = 250, top = 100.

And now StackView’s.
Axis = Vertical, Alignment = Fill, Distribution = Fill.

And people has Conflicting Constraints about every width.
I would like stackView width equal yellow Btn’s width.


So first, I attempted to change every Btn Content material Hugging Precedence.

GreenBtn CH(Content material Hugging)
Hori: 250
Verti: 250

RedBtn CH
Hori: 249
Verti: 250

YellowBtn CH
Hori: 248
Verti: 250

Not working,,,


So I additionally tried to vary Compressing Resistance(CR) prioirty

GreenBtn CR
Hori: 750
Verti: 750

RedBtn CR
Hori: 751
Verti: 750

YellowBtn CR
Hori: 752
Verti: 750

Nonetheless not work … StackView’s width = 100


img2

Lastly I attempted to vary every button’s required Precedence solely. (every CHCR worth setting defaultLow, defaultHigh)

GreenBtn width precedence = 997

RedBtn width precedence = 998

YellowBtn width precedence = 999

and Now stackView’s width has 250width( Yellow Btn width)

enter image description here


Question1. I ponder why would not modified stackView width once I modified CH worth or CR worth. what brought about my settings to be fallacious and methods to repair it?

Question2. I ponder why modified once I change buttons required precedence worth?

If the required precedence is similar as 1000, is not CHCR utilized otherwise relying on the precedence worth of CHCR? Is the required precedence over .defaultLow and .defaultHigh worth simply the boss?

Thanks for studying the lengthy query.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments