美文网首页
Masonry 比例设置multipliedBy与divided

Masonry 比例设置multipliedBy与divided

作者: BestBoy | 来源:发表于2019-12-14 16:16 被阅读0次

    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);
    
        }];
    

    相关文章

      网友评论

          本文标题:Masonry 比例设置multipliedBy与divided

          本文链接:https://www.haomeiwen.com/subject/luacnctx.html