Masonry 比例设置multipliedBy与dividedBy区别

Masonry 比例设置multipliedBy与dividedBy区别

multipliedBy是相对于自身比例(只能用于自身的比)dividedBy是相对于其他视图的比例(也可以用于自身的比),multipliedBy是相当于算数中的“除以”,dividedBy相当于算数中的“除”,看以下具体操作:

先查看效果图:

image
  • multipliedBy相对于自身的比
UIView *view1 = [[UIView alloc] init];
       view1.backgroundColor = [UIColor redColor];
       [self.view addSubview:view1];
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_offset(100);
        make.top.mas_equalTo(self.view.mas_top).mas_offset(100);
        make.width.mas_equalTo(view1.mas_height).multipliedBy(0.3);
        make.centerX.mas_equalTo(self.view.mas_centerX);
    }];
  • dividedBy相对于其他视图的比例
UIView *view2 = [[UIView alloc] init];
    view2.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:view2];
    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(view1.mas_bottom).mas_offset(100);
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.width.mas_equalTo(view1.mas_width);
        make.height.mas_equalTo(view1.mas_height).dividedBy(2);
        
    }];
  • dividedBy绿色线距self.view的1/5处,lineV.left除self.view.mas_right=5,相当于把self.view.withd划分五份
 UIView *lineV = [[UIView alloc] init];
    lineV.backgroundColor = [UIColor greenColor];
    [self.view addSubview:lineV];
    
    [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(self.view.mas_height);
        make.top.mas_equalTo(self.view.mas_top);
        make.width.mas_offset(1);
        make.left.mas_equalTo(self.view.mas_right).dividedBy(5);
        
    }];
  • multipliedBy红色线处于self.view的中间位置,linev2.left除以self.view.mas_right = 0.5
UIView *linev2 = [[UIView alloc] init];
    linev2.backgroundColor = [UIColor redColor];
    [self.view addSubview:linev2];
    
    [linev2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_top);
        make.height.mas_equalTo(self.view.mas_height);
        make.width.mas_offset(1);
        make.left.mas_equalTo(self.view.mas_right).multipliedBy(0.5);
    }];
  • dividedBy用于自身视图的比
UIView *lineV3 = [[UIView alloc] init];
    lineV3.backgroundColor = [UIColor greenColor];
    [self.view addSubview:lineV3];
    
    [lineV3 mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.mas_equalTo(self.view.mas_top);
       make.width.mas_offset(100);
        make.centerX.mas_equalTo(self.view.mas_centerX);
       make.height.mas_equalTo(lineV3.mas_width).dividedBy(2);

    }];
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • iOS_autoLayout_Masonry 概述 Masonry是一个轻量级的布局框架与更好的包装AutoLay...
    指尖的跳动阅读 4,954评论 1 4
  • 一、前言 关于苹果的布局一直是我比较纠结的问题,是写代码来控制布局,还是使用storyboard来控制布局呢?以前...
    iplaycodex阅读 7,225评论 0 1
  • 目前iOS开发中大多数页面都已经开始使用Interface Builder的方式进行UI开发了,但是在一些变化比较...
    大雪山大轮寺大轮明王阅读 5,496评论 1 2
  • (一)Masonry介绍 Masonry是一个轻量级的布局框架 拥有自己的描述语法 采用更优雅的链式语法封装自动布...
    木易林1阅读 7,075评论 0 3
  • 我是谁? 我是一个出生在广东偏远山区农村的人。祖辈世代是农民,从父亲开始,逐步有“读书跳龙门”的意识,至今,父亲的...
    Marvin_渊阅读 3,783评论 1 6