AutoLayout 代码添加约束

用NSLayoutConstraint添加View的Constraint

1.View的translatesAutoresizingMaskIntoConstraints设置为NO;
2.constraint对象的active设置为Yes,默认为NO;
3.必须添加View到superView;
4.对superView添加constraint。
如果对View添加constraint,会报错如下:
Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on view. Does the constraint reference something from outside the subtree of the view? That's illegal.
需要对superView设置constraint,不是对View设置constraint

你可能感兴趣的:(AutoLayout 代码添加约束)