自動布局Masonry

2021-07-07 06:40:59 字數 1597 閱讀 1798

通過cocoapod新增masonry三方, 或者手動新增三方

// 建立乙個view

uiview *view = [uiview new];

view.backgroundcolor

----------

= [uicolor purplecolor];

[self

.view addsubview:view];

// 300*300 居中顯示的矩形

[view mas_makeconstraints:^(masconstraintmaker *make) ];

// 1. make方法只負責增加新的約束, 但是不能同時出現兩條出現同一物件的約束, 否則會報錯

// 2. update方法針對上面的情況, 會更新約束, 以確保不會出現兩條相同的約束

// 3. remake方法會清除掉之前所有的約束, 並重新建立乙個

// 建立乙個view, 略小於上級檢視

uiview *view1 = [uiview new];

view1.backgroundcolor = [uicolor purplecolor];

// 一定要先將view貼到上級檢視上, 再建立約束, 否則會報錯

[self.view addsubview:view1];

// 偏移量15

// 兩個高度為150的view, 居中且等寬, 等間距, 寬度自動計算

uiview *view1 = [uiview new];

view1.backgroundcolor = [uicolor purplecolor];

[self.view addsubview:view1];

uiview *view2 = [uiview new];

view2.backgroundcolor = [uicolor purplecolor];

[self.view addsubview:view2];

[view1 mas_makeconstraints:^(masconstraintmaker *make) ];

[view2 mas_makeconstraints:^(masconstraintmaker *make) ];

#endif

Masonry布局控制項,自動換行

masonry偏移量offset答疑 make.top.equalto self.view offset 10 make.left.equalto self.view offset 10 make.bottom.equalto self.view offset 10 make.right.equal...

masonry布局說明

這個要根據情況而定,有時會很有用的。個人例項 左側輸入框右側按鈕按鈕變長有限制最小寬度,保持輸入框與按鈕左側距離,設定按鈕的壓縮性強 即一般不被拉伸 輸入框拉伸性強容易拉伸 self.button mas makeconstraints masconstraintmaker make self.bu...

iOS 自動布局Masonry工具包的簡化操作

特別說明,這是適合我自己的做法,其他人使用有可能引起不適,請在用過masonry的人員陪同下 用了masonry,感覺寫了一堆小圓點但是只是傳遞一兩個引數用起來特別麻煩,所以就偷懶吧。這些巨集定義只能寫在 mas makeconstraints呼叫的block裡面使用的,並且block引數變數名必須...