关于约束

关于约束

首先 Button.translatesAutoresizingMaskIntoConstraints = NO;
创建完按钮再添加约束
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:firstButton attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqualtoItem:self.view attribute:NSLayoutAttributeLeading multiplier:1.0f constant:20.f];
[self.view addConstraint:constraint];

总结一句话:始终遵循下面的规律:

  • viewA.attribute = viewB.attributs*multiplier + constant

你可能感兴趣的:(关于约束)