- Masonry 源码:https://github.com/Masonry/Masonry
使用第三方先看看Masonry框架的属性
@property (nonatomic, strong, readonly) MASConstraint *left; // 相邻左间距
@property (nonatomic, strong, readonly) MASConstraint *top;
@property (nonatomic, strong, readonly) MASConstraint *right;
@property (nonatomic, strong, readonly) MASConstraint *bottom;
@property (nonatomic, strong, readonly) MASConstraint *leading;// 头部 正常情况等价于left
@property (nonatomic, strong, readonly) MASConstraint *trailing;// 尾部 正常情况等价于right
@property (nonatomic, strong, readonly) MASConstraint *width;// 宽
@property (nonatomic, strong, readonly) MASConstraint *height;
@property (nonatomic, strong, readonly) MASConstraint *centerX; // 横向中点
@property (nonatomic, strong, readonly) MASConstraint *centerY;
@property (nonatomic, strong, readonly) MASConstraint *baseline; //文本基线
#if TARGET_OS_IPHONE
// 这写属性就相当于storyboard下面autolayout的pin设置的 对勾
@property (nonatomic, strong, readonly) MASConstraint *leftMargin; // 在原来左间距的基础上所做出的间距
@property (nonatomic, strong, readonly) MASConstraint *rightMargin;
@property (nonatomic, strong, readonly) MASConstraint *topMargin;
@property (nonatomic, strong, readonly) MASConstraint *bottomMargin;
@property (nonatomic, strong, readonly) MASConstraint *leadingMargin;
@property (nonatomic, strong, readonly) MASConstraint *trailingMargin;
@property (nonatomic, strong, readonly) MASConstraint *centerXWithinMargins;
@property (nonatomic, strong, readonly) MASConstraint *centerYWithinMargins;
#endif```
好,下面用实例演示下:首先在Appdelegate中先写个window
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
self.window.rootViewController = [[ViewController alloc]init];```