Masonry之初体验

  • 纯代码适配

  • 视图最基本适配方法介绍

  • 注意:必须先把视图加到父视图再进行适配

  • 注意:右边和底部偏移量为负数


  • 距离父视图 上下左右 各10个单位

UIView *backGroudView = [[UIView alloc] init];
    backGroudView.backgroundColor = [UIColor orangeColor];
    [self addSubview:backGroudView];
    [backGroudView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view).offset(10);
        make.left.equalTo(weakSelf.view).offset(10);
        make.bottom.equalTo(weakSelf.view).offset(-10);
        make.right.equalTo(weakSelf.view).offset(-10);
    }];
  • 视图靠左上角,宽高固定100

UIView *backGroudView = [[UIView alloc] init];
    backGroudView.backgroundColor = [UIColor orangeColor];
    [self addSubview:backGroudView];
    [backGroudView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view).offset(10);
        make.left.equalTo(weakSelf.view).offset(10);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(100);
    }];
  • 水平线居中,宽高固定
UIView *backGroudView = [[UIView alloc] init];
    backGroudView.backgroundColor = [UIColor orangeColor];
    [self addSubview:backGroudView];
    [backGroudView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view).offset(10);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(100);
       make.centerX.equalTo(weakSelf.view.mas_centerX);
    }];
  • 垂直线居中,宽高固定
UIView *backGroudView = [[UIView alloc] init];
    backGroudView.backgroundColor = [UIColor orangeColor];
    [self addSubview:backGroudView];
    [backGroudView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.view).offset(10);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(100);
      make.centerY.equalTo(weakSelf.view.mas_centerY);
    }];
  • 相对父视图居中,宽高固定
//方法一
UIView *backGroudView = [[UIView alloc] init];
    backGroudView.backgroundColor = [UIColor orangeColor];
    [self addSubview:backGroudView];
    [backGroudView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(100);
       make.centerY.equalTo(weakSelf.view.mas_centerY);
       make.centerX.equalTo(weakSelf.view.mas_centerX);
    }];

//方法二
UIView *backGroudView = [[UIView alloc] init];
    backGroudView.backgroundColor = [UIColor orangeColor];
    [self addSubview:backGroudView];
    [backGroudView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(200, 200));
        make.center.equalTo(weakSelf.view);
    }];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值