美文网首页
Masonry的简单使用

Masonry的简单使用

作者: 还是老徐ooo | 来源:发表于2018-05-07 14:45 被阅读3次

记录一下,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)Masonry是一个轻量级的布局框架,拥有自己的描述语法,采用更优雅的链式语法封装...

  • Masonry简单使用

    介绍:Masonry是一个轻量级的布局框架 拥有自己的描述语法 采用更优雅的链式语法封装自动布局 简洁明了 并具有...

  • Masonry的简单使用

    记录一下,Masonry的简单使用 /*UILabel *titleLab = [UILabel new];tit...

  • Masonry的简单使用

    首先,在正式使用Masonry之前,我们先来看看在xib中我们是如何使用AutoLayout 从图中我们可以看出,...

  • Masonry的简单使用

    Masonry是干什么的我就不废话了,相信用到它的人不会不知道,我们直接进入正题。 一、下面是Masonry给出的...

  • Masonry的简单使用

    有时候我们需要用代码设置约束,而苹果爸爸的NSLayoutConstraint看着实在让人恶心,简洁优雅的Maso...

  • Masonry的简单使用

    这里是Masonry给我们的属性 @property (nonatomic, strong, readonly) ...

  • Masonry的简单使用

    Masonry 实例化 redView 和 blueView 设置 redView 和 blueView 的约束 ...

  • Masonry的简单使用

    以前使用过masonry做页面布局,长时间不用,有些使用方法就有些遗忘了,所以今天就简单的复习一下 Masonry...

  • Masonry简单使用及如何利用Masonry约束宽相等

    Masonry简单使用及如何利用Masonry约束宽相等 其实Masonry封装的API和苹果官方的思路是非常一致...

网友评论

      本文标题:Masonry的简单使用

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