/**
* 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值
*
* @param axisType 轴线方向
* @param fixedSpacing 间隔大小
* @param leadSpacing 头部间隔
* @param tailSpacing 尾部间隔
*/
- (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType
withFixedSpacing:(CGFloat)fixedSpacing l
eadSpacing:(CGFloat)leadSpacing
tailSpacing:(CGFloat)tailSpacing;
/**
* 多个固定大小的控件的等间隔排列,变化的是间隔的空隙
*
* @param axisType 轴线方向
* @param fixedItemLength 每个控件的固定长度或者宽度值
* @param leadSpacing 头部间隔
* @param tailSpacing 尾部间隔
*/
- (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType
withFixedItemLength:(CGFloat)fixedItemLength
leadSpacing:(CGFloat)leadSpacing
tailSpacing:(CGFloat)tailSpacing;
使用与图解
1、纵向等间距排列
NSMutableArray *list = [[NSMutableArray alloc] initWithObjects:btn,btn1,btn2,btn3,btn31,btn4,btn5,btn6,btn7,btn9,btn10,btn11,btn12,btn13,btn14, nil];
[list mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:1 leadSpacing:1 tailSpacing:1];
[list mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(@15);
}];
19A5EC36-44FE-4725-805E-0A26C86849CF.png
2、纵向均分,各控件等高度排列
NSMutableArray *list = [[NSMutableArray alloc] initWithObjects:btn,btn1,btn2,btn3,btn31,btn4,btn5,btn6,btn7,btn9,btn10,btn11,btn12,btn13,btn14, nil];
[list mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedItemLength:20 leadSpacing:1 tailSpacing:1];
[list mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(@15);
}];
8E1DB17E-9C80-4486-9FF2-569A143784ED.png
3、横向均分,各控件等间距排列
NSMutableArray *list = [[NSMutableArray alloc] initWithObjects:btn,btn1,btn2,btn3,btn31,btn4,btn5,btn6,btn7,btn9,btn10,btn11,btn12,btn13,btn14, nil];
[list mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:1 leadSpacing:10 tailSpacing:10];
[list mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@60);
make.height.equalTo(@60);
}];
3435ADF2-C9F8-46FC-90E8-0EBB9C7FECE1.png
4、横向均分,各控件等宽度排列
NSMutableArray *list = [[NSMutableArray alloc] initWithObjects:btn,btn1,btn2,btn3,btn31,btn4,btn5,btn6,btn7,btn9,btn10,btn11,btn12,btn13,btn14, nil];
[list mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:10 leadSpacing:10 tailSpacing:10];
[list mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@60);
make.height.equalTo(@60);
}];
6B5D6E67-3B7B-4281-A91E-951C72608254.png
网友评论