LabelA的Content Hugging priority 的Horizontal值:251
LabelB的Content Hugging priority 的Horizontal值:250
LabelB被拉伸
LabelA的Content Compression Resistance priority 的Horizontal值:751
LabelB的Content Compression Resistance priority 的Horizontal值:750
LabelB被壓縮
Hugging priority 確定view有多大的優(yōu)先級(jí)阻止自己變大。
Compression Resistance priority確定有多大的優(yōu)先級(jí)阻止自己變小丈钙。
用代碼來(lái)實(shí)現(xiàn)
setContentCompressionResistancePriority(抗壓縮)随珠,這個(gè)值越低旅择,就會(huì)在寬度不夠的情況下腺阳,被壓縮。常見(jiàn)的視圖默認(rèn)給的值是UILayoutPriorityDefaultHigh = 750婿奔。若是多個(gè)視圖是默認(rèn)值撵颊,會(huì)被系統(tǒng)認(rèn)為更早被addSubview的視圖該值更小尖淘!
[label1 setContentCompressionResistancePriority:758 forAxis:(UILayoutConstraintAxisHorizontal)];
setContentHuggingPriority(抗拉伸)奕锌,這個(gè)值越低,就會(huì)在寬度多余的情況下村生,被拉伸惊暴。常見(jiàn)的視圖默認(rèn)給的值是UILayoutPriorityDefaultLow = 250。若是多個(gè)視圖是默認(rèn)值趁桃,會(huì)被系統(tǒng)認(rèn)為更早被addSubview的值更辛苫啊!
[label1 setContentHuggingPriority:300 forAxis:(UILayoutConstraintAxisHorizontal)];