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

使用第三方先看看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];```
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,035评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,498评论 4 61
  • 一周目 2017.2 感觉作者是有观察力却不太能分析,没有活明白的人。陷入自己的三观局限之中,从而写下了自己的生命...
    弦安阅读 3,427评论 0 0
  • 在“互联网+”的时代背景下,运营的角色和定位是越来越重要了。 而对于一名刚刚进入互联网运营的小伙伴来说,职业发展路...
    Icebear白熊阅读 1,364评论 0 1
  • 1、下载:到ANT官方网站http://ant.apache.org/下载最新版本,解压后即可。2、配置环境变量:...
    proud2008阅读 1,369评论 0 0

友情链接更多精彩内容