Masonry的使用

来源:互联网 发布:mysql修复数据库命令 编辑:程序博客网 时间:2024/06/06 16:26

Masonry是一个轻量级的布局框架,拥有自己的描述语法,采用更优雅的链式语法封装自动布局,简洁明了并具有高可读性,而且同时支持 iOS 和 Max OS X。

这里是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;   //首部@property (nonatomic, strong, readonly) MASConstraint *trailing;  //尾部@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; //文本基线


现在我们纯代码来创建一个UITableViewCell并使用Masonry给Cell里面的控件设置约束。如图所示的Cell



代码如下:



以上代码已经给Cell里面的控件设置好了约束,现在我们把它加载到UITableView中查看效果





运行后得到效果如图:


原创粉丝点击