Masonry 比例设置multipliedBy与divided

2019-12-14  本文已影响0人  BestBoy

Masonry 比例设置multipliedBy与dividedBy区别

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

先查看效果图:

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

    }];
上一篇下一篇

猜你喜欢

热点阅读