lyt

Apache 2.0 许可证
Objective-C
iOS

1 张图片

作者

描述

一个 UIView 分类,使自动布局(更多)易于阅读且不那么冗长。写下这个

[view lyt_centerInParent];

而不是

NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint
    constraintWithItem:view attribute:NSLayoutAttributeCenterX
    relatedBy:NSLayoutRelationEqual toItem:view.superview
    attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0];

[view.superview addConstraint:centerXConstraint];

NSLayoutConstraint *centerYConstraint = [NSLayoutConstraint
    constraintWithItem:view
    attribute:NSLayoutAttributeCenterY
    relatedBy:NSLayoutRelationEqual toItem:view2
    attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0];

[view.superview addConstraint:centerYConstraint];

标签