- 等比例 :
如果給出一個(gè) button一死,不要寫(xiě)死button 的寬高逃片,否則不同設(shè)備顯示會(huì)有偏差空郊,所以,我們可以用等比例算出button的寬高
dividedBy() 算短邊
multipliedBy()算長(zhǎng)邊
例子 寬高 3/1 丈攒,可用 make.height.equalTo(view.mas_width).dividedBy(3) 算出 高度
代碼:寬高比例 7:1 渡嚣,寬(左右約束) 高(通過(guò)比例計(jì)算)
image.png
- 排列N個(gè)控件
如果你想排列 N個(gè)控件,不需要算出每個(gè)控件高度
/**
- distribute with fixed spacing
- @param axisType 橫排還是豎排
- @param fixedSpacing 兩個(gè)控件間隔
- @param leadSpacing 第一個(gè)控件與邊緣的間隔
- @param tailSpacing 最后一個(gè)控件與邊緣的間隔
*/
- (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedSpacing:(CGFloat)fixedSpacing leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing;
/**
- distribute with fixed item size
- @param axisType 橫排還是豎排
- @param fixedItemLength 控件的寬或高
- @param leadSpacing 第一個(gè)控件與邊緣的間隔
- @param tailSpacing 最后一個(gè)控件與邊緣的間隔
*/
- (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedItemLength:(CGFloat)fixedItemLength leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing;
例:
image.png
如果 橫向排列 設(shè)置高肥印,反之你懂得
效果:
image.png
獲取 VIew 的真實(shí) 數(shù)據(jù)frame:
方法 1. [self.view layoutIfNeeded];
方法 2.[view systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height);
自動(dòng)根據(jù)bar 高度設(shè)置的引導(dǎo)屬性值绝葡,舉個(gè)例子:
存在navigationBar 時(shí)深碱,mas_topLayoutGuideBottom 相當(dāng)于 增加了44。
不存在navigationBar 時(shí)藏畅,mas_topLayoutGuideBottom 相對(duì)于 0 敷硅。
mas_topLayoutGuide;// navgationBar 相關(guān),
mas_topLayoutGuideTop;
mas_topLayoutGuideBottom;
mas_bottomLayoutGuide;// tabbar toolbar 相關(guān)
mas_bottomLayoutGuideTop;
mas_bottomLayoutGuideBottom;