Masonry(第三方库)的使—代码实现屏幕适配

#import"Masonry"

实现效果图

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self testBasicLayout];
    [self testThreeLayout];
}
- (void)testThreeLayout
{
    UIView *redView = [[UIView alloc] init];
    redView.backgroundColor = [UIColor redColor];
    [self.view addSubview:redView];
    
    UIView *blueView = [[UIView alloc] init];
    blueView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:blueView];
    
    UIView *greenView = [[UIView alloc] init];
    greenView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:greenView];
    
    [redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(50);
        make.left.mas_equalTo(50);
        make.right.mas_equalTo(-50);
        make.height.mas_equalTo(100);
    }];
    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(redView.mas_bottom).offset(50);//偏移量 默认0
        make.left.mas_equalTo(50);
        make.height.mas_equalTo(100);
        //make.width.mas_equalTo(100);
    }];
    [greenView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(redView.mas_bottom).offset(50);
        make.right.mas_equalTo(-50);
        make.height.mas_equalTo(100);
        make.width.mas_equalTo(100);
        
        //间隔固定,宽度相等
        make.left.mas_equalTo(blueView.mas_right).offset(50);
        make.width.mas_equalTo(blueView.mas_width);
    }];
}
- (void)testBasicLayout
{
    //靠右对齐,100x100,top-50 right-50
    UIView *redView = [[UIView alloc] init];
    redView.backgroundColor = [UIColor redColor];
    [self.view addSubview:redView];
    //block重要参数:mark参数,设置make的属性。控制布局
    /*
    [redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(100);
        make.top.mas_equalTo(50);
        make.right.mas_equalTo(-50);
        
    }];
     */
    [redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(50);
        make.left.mas_equalTo(50);
        make.right.mas_equalTo(-50);
        make.height.mas_equalTo(100);
    }];
}
View Code

 

转载于:https://www.cnblogs.com/caolongs/p/4774113.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值