Masonry 比例設置multipliedBy與dividedBy區(qū)別

Masonry 比例設置multipliedBy與dividedBy區(qū)別

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

    }];
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • iOS_autoLayout_Masonry 概述 Masonry是一個輕量級的布局框架與更好的包裝AutoLay...
    指尖的跳動閱讀 1,315評論 1 4
  • 一、前言 關于蘋果的布局一直是我比較糾結的問題,是寫代碼來控制布局,還是使用storyboard來控制布局呢?以前...
    iplaycodex閱讀 2,729評論 0 1
  • 目前iOS開發(fā)中大多數頁面都已經開始使用Interface Builder的方式進行UI開發(fā)了,但是在一些變化比較...
    大雪山大輪寺大輪明王閱讀 1,691評論 1 2
  • (一)Masonry介紹 Masonry是一個輕量級的布局框架 擁有自己的描述語法 采用更優(yōu)雅的鏈式語法封裝自動布...
    木易林1閱讀 2,573評論 0 3
  • 我是誰? 我是一個出生在廣東偏遠山區(qū)農村的人。祖輩世代是農民,從父親開始,逐步有“讀書跳龍門”的意識,至今,父親的...
    Marvin_淵閱讀 681評論 1 6

友情鏈接更多精彩內容