Masonry的简单使用

记录一下,Masonry的简单使用

UIView *spView = [[UIView alloc] init];
spView.backgroundColor = [UIColor grayColor];
[self.view addSubview:spView];

UIView *blue = [UIView new];
blue.backgroundColor = [UIColor blueColor];
[spView addSubview:blue];
self.blue = blue;

UIView *red = [UIView new];
red.backgroundColor = [UIColor redColor];
[spView addSubview:red];
self.red = red;


[spView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.mas_equalTo(self.view).with.mas_offset(UIEdgeInsetsMake(80, 50, 60, 50));
}];

/*
UILabel *titleLab = [UILabel new];
titleLab.text = @"第一种情况情况情况情况情况情况情况情况情况情况情况情况情况情况情况情况情况情况情况情况 ";
titleLab.backgroundColor = [UIColor greenColor];
titleLab.numberOfLines = 0;
[spView addSubview:titleLab];

[titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.top.right.mas_equalTo(spView).mas_offset(UIEdgeInsetsMake(10, 10, 0, 10));
    
}];
*/

/*
 方式 1 上下排列
[blue mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.and.right.and.top.mas_equalTo(spView).mas_offset(UIEdgeInsetsMake(10, 10, 0, 10));
    make.height.mas_equalTo(100);
}];

[red mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.and.right.mas_equalTo(spView).mas_offset(UIEdgeInsetsMake(0, 10, 0, 10));
    make.top.mas_equalTo(blue.mas_bottom).mas_offset(10);
    make.height.mas_equalTo(blue.mas_height).multipliedBy(0.5);
}];
*/

/*
//方式 2 左右等宽高排列
[blue mas_makeConstraints:^(MASConstraintMaker *make) {

     make.left.mas_equalTo(spView).mas_offset(10);
     make.right.mas_equalTo(red.mas_left).mas_offset(-10);
     make.height.mas_equalTo(100);
     
     make.centerY.mas_equalTo(spView);
     make.width.mas_equalTo(red);
     make.height.mas_equalTo(red);
 }];
 
 [red mas_makeConstraints:^(MASConstraintMaker *make) {
     
     make.left.mas_equalTo(blue.mas_right);
     make.right.mas_equalTo(spView).mas_offset(-10);
     
     make.centerY.mas_equalTo(spView);

 }];

*/

/*
//方式 3 左右排列 左固定宽 右边不定宽
[blue mas_makeConstraints:^(MASConstraintMaker *make) {

    make.left.mas_equalTo(spView).mas_offset(10);
    make.right.mas_equalTo(red.mas_left).mas_offset(-10);
    
    make.size.mas_equalTo(CGSizeMake(100, 100));
    make.centerY.mas_equalTo(spView);
    make.height.mas_equalTo(red);
}];

[red mas_makeConstraints:^(MASConstraintMaker *make) {
    
    make.centerY.mas_equalTo(spView);
    
    make.right.mas_equalTo(spView).mas_offset(-10);
    make.left.mas_equalTo(blue.mas_right);
    
}];
*/

/*
//方式 4 左右排列 右固定宽 左边不定宽
[red mas_makeConstraints:^(MASConstraintMaker *make) {

    make.size.mas_equalTo(CGSizeMake(50, 100));
    make.top.mas_equalTo(spView).mas_offset(50);
    make.right.mas_equalTo(spView).mas_offset(-10);
    make.height.mas_equalTo(blue);
}];

[blue mas_makeConstraints:^(MASConstraintMaker *make) {
    
    make.left.mas_equalTo(spView).mas_offset(10);
    make.right.mas_equalTo(red.mas_left).mas_offset(-10);
    // make.top.mas_equalTo(spView).mas_offset(50); //方法1
    make.top.mas_equalTo(red.mas_top); //方法2

}];
*/

/*
//方式 5 中间对齐
UILabel *nameLab = [UILabel new];
nameLab.text = @"黄药师";
nameLab.font = JHFont(30);
nameLab.backgroundColor = [UIColor yellowColor];
[spView addSubview:nameLab];

UILabel *jobLab = [UILabel new];
jobLab.text = @"桃花岛岛主";
jobLab.font = JHFont(20);
jobLab.backgroundColor = [UIColor orangeColor];
[spView addSubview:jobLab];

UILabel *nickLab = [UILabel new];
nickLab.text = @"“天下五绝”之“东邪”";
nickLab.font = JHFont(10);
nickLab.backgroundColor = [UIColor brownColor];
[spView addSubview:nickLab];


[nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.top.mas_equalTo(spView).mas_offset(10);
    make.right.mas_equalTo(jobLab.mas_left).mas_offset(-10);
}];

[jobLab mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(nameLab.mas_right);
    make.right.mas_equalTo(nickLab.mas_left).mas_offset(-10);
    make.centerY.mas_equalTo(nameLab.mas_centerY);

}];

[nickLab mas_makeConstraints:^(MASConstraintMaker *make) {
   
    make.left.mas_equalTo(jobLab.mas_right);
    make.right.mas_equalTo(spView).mas_offset(-10);
    make.centerY.mas_equalTo(nameLab.mas_centerY);

}];

*/

/*
//更新约束,动画效果
[self.blue mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(200);
}];
[UIView animateWithDuration:1 animations:^{
[self.view layoutIfNeeded];
}];
*/

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • (一)Masonry介绍 Masonry是一个轻量级的布局框架 拥有自己的描述语法 采用更优雅的链式语法封装自动布...
    木易林1阅读 2,372评论 0 3
  • Masonry是一个轻量级的布局框架,拥有自己的描述语法,采用更优雅的链式语法封装自动布局,简洁明了并具有高可读性...
    3dcc6cf93bb5阅读 1,802评论 0 1
  • 我们的生活有这么多的障碍 真他妈有意思 这种逻辑就叫做黑色幽默——王小波 隔着屏幕看人会好看些 透过窗子看人世会亲...
    梦里缤纷共醉有乐趣阅读 429评论 0 0
  • 姓名:丁美 公司:宁波大发化纤有限公司 期数:六项精进234期学员 组号:谦虚一组 【日精进打卡第14天】 【知~...
    丁美阅读 112评论 0 0
  • 哈哈哈
    大平蒯阅读 178评论 0 0