最近看项目代码,用代码重新进行了约束,但是看不懂,于是搜索了一下。
layout if needed//刷新约束的改变
函数说明:
[NSLayoutConstraint constraintWithItem :(id)item
attribute:(NSLayoutAttribute)attribute
relatedBy:(NSLayoutRelation)relation
toItem:(id)otherItem
attribute:(NSLayoutAttribute)otherAttribute
multiplier:(CGFloat)multiplier
constant:(CGFloat)constant ]
item :指定约束左边的视图view1;
attribute:指定view1的属性
//视图属性值如下
NSLayoutAttributeLeft// 左侧
NSLayoutAttributeRight//右侧
NSLayoutAttributeTop//上方
NSLayoutAttributeBottom//下方
NSLayoutAttributeLeading//首部
NSLayoutAttributeTrailing//尾部
NSLayoutAttributeWidth//宽度
NSLayoutAttributeHeight//高度
NSLayoutAttributeCenterX//x轴中心
NSLayoutAttributeCenterY//y轴中心
NSLayoutAttributeBaseLine//文本底线标线
NSLayoutAttributeNotAnAttribute = 0;//没有属性
relation:指定左右两边的视图关系,relation
//视图属性之间的关系值如下
NSLayoutRelationLessThanOrEqual = -1;//小等于
NSLayoutRelationEqual = 0;//等于
NSLayoutRelationGreaterOrEqual = 1;//大于等于
otherItem:指定约束右边的视图view2
otherAttribute:指定view2的属性,
multiplier:指定一个与view2属性相乘的乘数
constant:指定一个与view2属性相加的浮点数
函数的对照公式如下:
view1.attr<relation>view2.attr * multiplier +constant
//如果你的设置里面的约束不需要dier个view。要将otherItem 设为nil,otherAttribute设为NSLayoutAttributedNotAnAttribute