// 创建两个按钮
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn1 setFrame:CGRectMake(200, 210, 100, 40)];
[btn1 setTitle:@"点击" forState:UIControlStateNormal];
[self.view addSubview:btn1];
[btn1 setTranslatesAutoresizingMaskIntoConstraints:NO];
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn2 setFrame:CGRectMake(200, 260, 100, 40)];
[btn2 setTitle:@"按钮" forState:UIControlStateNormal];
[self.view addSubview:btn2];
[btn2 setTranslatesAutoresizingMaskIntoConstraints:NO];
// 使用 VFL控制按钮位置
// 参数
// 1.可视化格式语言字符串
// 2.格式选择
// 3.所有参加格式化布局数据的字典,串nil也可以的
//4.所有参加格式化布局的对象字典
// 返回值:根据VFL生成的一组约束
NSDictionary *dict = NSDictionaryOfVariableBindings(btn1,btn2);
// @"H:[btn1]-50-|" [btn1]左右如果有|-50-或者-50-|说明它是在btn1左右个间距50是个点得距离
NSArray *arrayH1 = [NSLayoutConstraintconstraintsWithVisualFormat:@"H:[btn1]-50-|" options:0 metrics:nil views:dict];
[self.view addConstraints:arrayH1];
NSArray *arrayH2 = [NSLayoutConstraintconstraintsWithVisualFormat:@"H:[btn2]-50-|" options:0 metrics:nil views:dict];
[self.view addConstraints:arrayH2];
// [self.view addConstraints:arrayH1];
// [self.view addConstraints:arrayH2];
// 垂直方向的间距
NSArray *arrayV = [NSLayoutConstraintconstraintsWithVisualFormat:@"V:|-60-[btn1(20)]-20-[btn2]" options:0metrics:nil views:dict];
[self.view addConstraints:arrayV];