相对布局 Masonry 基本使用

本文介绍使用Masonry库进行链式语法布局的实际操作方法,包括UIImageView与UILabel的定位及大小设置,并展示了如何通过链式语法简洁地组织视图。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


// 链式语法的基本操作

#import "RootViewController.h"

#import "Masonry.h"

@interface RootViewController ()


@end


@implementation RootViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

  

 [_imageMusic mas_makeConstraints:^(MASConstraintMaker *make) {

        

        make.top.equalTo(self.viewBottom).with.offset(10);

        make.left.equalTo(self.viewBottom).with.offset(20);

        make.bottom.equalTo(self.viewBottom).with.offset(-10);

        

        make.width.mas_equalTo(40);

        make.height.mas_equalTo(40);

        _imageMusic.layer.cornerRadius = 20.0f;

        _imageMusic.clipsToBounds = YES;

        

    }];

    

    

    

    self.labelMusic = [[UILabel alloc] init];

    //    self.labelMusic.backgroundColor = [UIColor yellowColor];

    self.labelMusic.textAlignment = NSTextAlignmentCenter;

    self.labelMusic.textColor = [UIColor whiteColor];

    [self.viewBottom addSubview:_labelMusic];

    

    [_labelMusic mas_updateConstraints:^(MASConstraintMaker *make) {

        

        make.top.equalTo(_imageMusic.mas_top).with.offset(0);

        make.left.equalTo(_imageMusic.mas_right).with.offset(15);

        make.right.equalTo(self.viewBottom).with.offset(-80);

        make.height.mas_equalTo(40);

        

    }];

    

    self.buttPlay = [UIButton buttonWithType:UIButtonTypeCustom];

    [self.buttPlay setImage:[UIImage imageNamed:@"iconfont-bofang"] forState:UIControlStateNormal];

    // 增加butt 点击事件

    [self.buttPlay addTarget:self action:@selector(clickPlayMusic:) forControlEvents:UIControlEventTouchUpInside];

    [self.viewBottom addSubview:_buttPlay];

    

    [_buttPlay mas_updateConstraints:^(MASConstraintMaker *make) {

        

        make.top.equalTo(_imageMusic.mas_top).with.offset(0);

        make.left.equalTo(_labelMusic.mas_right).with.offset(10);

        make.right.equalTo(self.viewBottom.mas_right).with.offset(-20);

        make.height.mas_equalTo(40);

    }];



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值