您的位置:首页 > 其它

Massary屏幕适配,自动布局

2016-06-26 00:00 375 查看
摘要: 开发往往需要适配多种屏幕,一种屏幕写一套布局太过于麻烦,所以用Massary来根据不同屏幕自动布局,简化开发,提高效率。

- (void)viewDidLoad {

[super viewDidLoad];

//    添加红蓝两个控件

UIView *blueView = [[UIView alloc]init];

blueView.backgroundColor = [UIColor blueColor];

blueView.translatesAutoresizingMaskIntoConstraints = NO;

[self.view addSubview:blueView];

UIView *redView = [[UIView alloc]init];

redView.backgroundColor = [UIColor redColor];

redView.translatesAutoresizingMaskIntoConstraints = NO;

[self.view addSubview:redView];

//    添加约束

/**

练习1:

*/

/*

[blueView mas_makeConstraints:^(MASConstraintMaker *make) {

//        固定大小用mas_equalTo

make.width.mas_equalTo(100);

make.height.mas_equalTo(100);

//        与其他控件比较equalTo

make.centerX.equalTo(self.view.mas_centerX);

make.centerY.equalTo(self.view.mas_centerY);

}];

*/

/**

练习2:

*/

/*

[blueView mas_makeConstraints:^(MASConstraintMaker *make) {

make.left.equalTo(self.view.mas_left).offset(30);

make.bottom.equalTo(self.view.mas_bottom).offset(-30);

make.right.equalTo(redView.mas_left).offset(-30);

make.height.mas_equalTo(50);

}];

[redView mas_makeConstraints:^(MASConstraintMaker *make) {

make.right.equalTo(self.view.mas_right).offset(-30);

make.bottom.equalTo(blueView.mas_bottom);

make.height.equalTo(blueView.mas_height);

make.width.equalTo(blueView.mas_width);

}];

*/

/**

练习3:

*/

/*

[blueView mas_makeConstraints:^(MASConstraintMaker *make) {

make.left.equalTo(self.view.mas_left).offset(30);

make.top.equalTo(self.view.mas_top).offset(30);

make.right.equalTo(self.view.mas_right).offset(-30);

make.height.mas_equalTo(50);

}];

[redView mas_makeConstraints:^(MASConstraintMaker *make) {

make.right.equalTo(blueView.mas_right);

make.top.equalTo(blueView.mas_bottom).offset(30);

make.height.equalTo(blueView.mas_height);

make.left.equalTo(blueView.mas_centerX);

}];

*/

//    删除约束,重新添加

[blueView mas_remakeConstraints:^(MASConstraintMaker *make) {

}];

//    更新约束

[blueView mas_updateConstraints:^(MASConstraintMaker *make) {

}];

}

//方法一,array 的 mas_distributeViewsAlongAxis
/**
*  多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值
*
*  @param axisType        轴线方向
*  @param fixedSpacing    间隔大小
*  @param leadSpacing     头部间隔
*  @param tailSpacing     尾部间隔
*/
//    MASAxisTypeHorizontal  水平
//    MASAxisTypeVertical    垂直

[arrayList mas_distributeViewsAlongAxis:MASAxisTypeHorizontal
withFixedSpacing:20
leadSpacing:5
tailSpacing:5];
[arrayList mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(60);
make.height.mas_equalTo(100);
}];

/**
*  多个固定大小的控件的等间隔排列,变化的是间隔的空隙
*
*  @param axisType        轴线方向
*  @param fixedItemLength 每个控件的固定长度或者宽度值
*  @param leadSpacing     头部间隔
*  @param tailSpacing     尾部间隔
*/
[arrayList mas_distributeViewsAlongAxis:MASAxisTypeVertical
withFixedItemLength:60
leadSpacing:40
tailSpacing:10];
[arrayList mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(100);
//        make.height.mas_equalTo(100);
make.left.mas_equalTo(20);
make.right.mas_equalTo(-20);
}];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息