1.添加约束(系统)

a.一个约束(上下左右)

+(instancetype)constraintWithItem:(id)view1 attribute:(NSLayoutAttribute)attr1 relatedBy:(NSLayoutRelation)relation toItem:(id)view2 attribute:(NSLayoutAttribute)attr2 multiplier:(CGFloat)multiplier constant:(CGFloat)c;

b.一组约束(水平,垂直)

+ (NSArray *)constraintsWithVisualFormat:(NSString *)format options:(NSLayoutFormatOptions)opts metrics:(NSDictionary *)metrics views:(NSDictionary *)views;

2.VFL常用参数

 功能        表达式

  水平方向          H:
垂直方向        V: Views         [view]
SuperView(父视图)  |
关系         >=,==,<=
空间,间隙       -
优先级        @value

3.使用VFL

a.视图字典

NSDictionary *dict2 = NSDictionaryOfVariableBindings(button,button1);

b.参数字典

NSDictionary *metrics = @{@"padding":@,@"height":@};

c.具体使用

 /* [button]-[button1] :button和button1为同一级别的视图,默认间距为 8 */
NSArray *array3 = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[button1]-|" options: metrics:nil views:dict2];
NSArray *array4 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[button]-padding-[button1(==height)]" options: metrics:metrics views:dict2];
[self.view addConstraints:array3];
[self.view addConstraints:array4];
05-11 18:01