- (void)viewDidLoad
{
[super viewDidLoad];
UILabel *label = [[UILabel alloc]init];
label.text = @"AutoLayout";
label.backgroundColor = [UIColor lightGrayColor];
self.view.translatesAutoresizingMaskIntoConstraints = NO;
label.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:label];
//AutoLayout, 创建约束对象
//view1.attr1 = view2.attr2 * multiplier + constant;
NSLayoutConstraint *constraint1 = [NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:-10];
NSLayoutConstraint *constraint2 = [NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1 constant:-10];
//给控件(子视图)加约束
[self.view addConstraints:@[constraint1, constraint2]];
}