美文网首页iOS Coding程序员iOS开发记录
第三方Masonry-实现纯代码自动布局(1)

第三方Masonry-实现纯代码自动布局(1)

作者: 渴wang | 来源:发表于2015-10-30 14:49 被阅读241次

    使用第三方先看看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];```

    相关文章

      网友评论

        本文标题:第三方Masonry-实现纯代码自动布局(1)

        本文链接:https://www.haomeiwen.com/subject/kymfhttx.html