[NSLayoutConstraint constraintWithItem:(id)item attribute:(NSLayoutAttribute)attribute relatedBy:(NSLayoutRelation)relation toItem:(id)otherItem attribute:(NSLayoutAttribute)otherAttribute multiplier:(CGFloat)multiplier constant:(CGFloat)constant]
參數(shù)說明:
第一個(gè)參數(shù):指定約束左邊的視圖view1
第二個(gè)參數(shù):指定view1的屬性attr1丹墨,具體屬性見文末胜茧。
第三個(gè)參數(shù):指定左右兩邊的視圖的關(guān)系relation卸伞,具體關(guān)系見文末噩咪。
第四個(gè)參數(shù):指定約束右邊的視圖view2
第五個(gè)參數(shù):指定view2的屬性attr2蹬碧,具體屬性見文末。
第六個(gè)參數(shù):指定一個(gè)與view2屬性相乘的乘數(shù)multiplier
第七個(gè)參數(shù):指定一個(gè)與view2屬性相加的浮點(diǎn)數(shù)constant
注意:
1.如果你想設(shè)置的約束里不需要第二個(gè)view啤月,要將第四個(gè)參數(shù)設(shè)為nil俩由,第五個(gè)參數(shù)設(shè)為NSLayoutAttributeNotAnAttribute
附視圖的屬性和關(guān)系的值:
typedef NS_ENUM(NSInteger, NSLayoutRelation) {
NSLayoutRelationLessThanOrEqual = -1,? ? ? ? ? //小于等于
NSLayoutRelationEqual = 0,? ? ? ? ? ? ? ? ? ? //等于
NSLayoutRelationGreaterThanOrEqual = 1,? ? ? ? //大于等于
};
typedef NS_ENUM(NSInteger, NSLayoutAttribute) {
NSLayoutAttributeLeft = 1,? ? ? ? ? ? ? ? ? ? //左側(cè)
NSLayoutAttributeRight,? ? ? ? ? ? ? ? ? ? ? ? //右側(cè)
NSLayoutAttributeTop,? ? ? ? ? ? ? ? ? ? ? ? ? //上方
NSLayoutAttributeBottom,? ? ? ? ? ? ? ? ? ? ? //下方
NSLayoutAttributeLeading,? ? ? ? ? ? ? ? ? ? ? //首部
NSLayoutAttributeTrailing,? ? ? ? ? ? ? ? ? ? //尾部
NSLayoutAttributeWidth,? ? ? ? ? ? ? ? ? ? ? ? //寬度
NSLayoutAttributeHeight,? ? ? ? ? ? ? ? ? ? ? //高度
NSLayoutAttributeCenterX,? ? ? ? ? ? ? ? ? ? ? //X軸中心
NSLayoutAttributeCenterY,? ? ? ? ? ? ? ? ? ? ? //Y軸中心
NSLayoutAttributeBaseline,? ? ? ? ? ? ? ? ? ? //文本底標(biāo)線
NSLayoutAttributeNotAnAttribute = 0? ? ? ? ? ? //沒有屬性
};