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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容