侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Massary屏幕适配,自动布局

2024-05-14 星期二 / 0 评论 / 0 点赞 / 86 阅读 / 4875 字

- (void)viewDidLoad { [super viewDidLoad]; // 添加红蓝两个控件 UIView *blueView = [[UIView alloc]init];

- (void)viewDidLoad {    [super viewDidLoad];    //    添加红蓝两个控件    UIView *blueView = [[UIView alloc]init];    blueView.backgroundColor = [UIColor blueColor];    blueView.translatesAutoresizingMaskIntoConstraints = NO;    [self.view addSubview:blueView];        UIView *redView = [[UIView alloc]init];    redView.backgroundColor = [UIColor redColor];    redView.translatesAutoresizingMaskIntoConstraints = NO;    [self.view addSubview:redView];        //    添加约束    /** 练习1: */        /*    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {        //        固定大小用mas_equalTo        make.width.mas_equalTo(100);        make.height.mas_equalTo(100);//        与其他控件比较equalTo        make.centerX.equalTo(self.view.mas_centerX);        make.centerY.equalTo(self.view.mas_centerY);    }];*/        /**     练习2:     */   /*    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {        make.left.equalTo(self.view.mas_left).offset(30);        make.bottom.equalTo(self.view.mas_bottom).offset(-30);        make.right.equalTo(redView.mas_left).offset(-30);        make.height.mas_equalTo(50);    }];        [redView mas_makeConstraints:^(MASConstraintMaker *make) {               make.right.equalTo(self.view.mas_right).offset(-30);        make.bottom.equalTo(blueView.mas_bottom);        make.height.equalTo(blueView.mas_height);        make.width.equalTo(blueView.mas_width);    }];   */    /**     练习3:     */    /*    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {        make.left.equalTo(self.view.mas_left).offset(30);        make.top.equalTo(self.view.mas_top).offset(30);        make.right.equalTo(self.view.mas_right).offset(-30);        make.height.mas_equalTo(50);            }];    [redView mas_makeConstraints:^(MASConstraintMaker *make) {        make.right.equalTo(blueView.mas_right);        make.top.equalTo(blueView.mas_bottom).offset(30);        make.height.equalTo(blueView.mas_height);        make.left.equalTo(blueView.mas_centerX);    }];     *///    删除约束,重新添加    [blueView mas_remakeConstraints:^(MASConstraintMaker *make) {            }];//    更新约束    [blueView mas_updateConstraints:^(MASConstraintMaker *make) {            }];    }
//方法一,array 的 mas_distributeViewsAlongAxis/** *  多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * *  @param axisType        轴线方向 *  @param fixedSpacing    间隔大小 *  @param leadSpacing     头部间隔 *  @param tailSpacing     尾部间隔 *///    MASAxisTypeHorizontal  水平//    MASAxisTypeVertical    垂直[arrayList mas_distributeViewsAlongAxis:MASAxisTypeHorizontal                       withFixedSpacing:20                            leadSpacing:5                            tailSpacing:5];[arrayList mas_makeConstraints:^(MASConstraintMaker *make) {    make.top.mas_equalTo(60);    make.height.mas_equalTo(100);}];/** *  多个固定大小的控件的等间隔排列,变化的是间隔的空隙 * *  @param axisType        轴线方向 *  @param fixedItemLength 每个控件的固定长度或者宽度值 *  @param leadSpacing     头部间隔 *  @param tailSpacing     尾部间隔 */[arrayList mas_distributeViewsAlongAxis:MASAxisTypeVertical                    withFixedItemLength:60                            leadSpacing:40                            tailSpacing:10];[arrayList mas_makeConstraints:^(MASConstraintMaker *make) {    //        make.top.mas_equalTo(100);    //        make.height.mas_equalTo(100);    make.left.mas_equalTo(20);    make.right.mas_equalTo(-20);}];

 

广告 广告

评论区