第三方的http://adad184.com/2014/09/28/use-masonry-to-quick-solve-autolayout/ 使用说明
自己项目中用到 做个简单的说明
eg:是一个Cell内部控件的布局
__weaktypeof(self) weakSelf =self;
//创建约束
[_posmOwnNameLabelmas_makeConstraints:^(MASConstraintMaker *make) {
//当前控件到Cell的contentView 的左边和上 距离10
make.left.equalTo(weakSelf.contentView).offset(10);
make.top.equalTo(weakSelf.contentView).offset(10);
//当前控件的宽度为这边kDeviceSize.width 屏幕的宽度
make.width.equalTo((kDeviceSize.width-40)/3);
//当前控件到Cell得contentView下的距离为-10 (也就是当前控件的底部位于contentView的上面10的距离)
make.bottom.equalTo(weakSelf.contentView).offset(-10);
}];
[_posmDescLabelmas_makeConstraints:^(MASConstraintMaker *make) {
//当期控件的上、下、宽度 与 上个控件的约束设置一致
make.width.top.bottom.equalTo(weakSelf.posmOwnNameLabel);
// 当前控件的左边启示约束到上一个控件右边的距离约束设置为5
make.left.equalTo(weakSelf.posmOwnNameLabel.right).offset(5);
}];
[_posmQuantityLabelmas_makeConstraints:^(MASConstraintMaker *make) {
make.width.top.bottom.equalTo(weakSelf.posmOwnNameLabel);
make.left.equalTo(weakSelf.posmDescLabel.right).offset(5);
}];
[_selectImagemas_makeConstraints:^(MASConstraintMaker *make) {
//当前控件的左边道contentView右边的约束为-10 (距离conteView位置还有10的距离)
make.right.equalTo(weakSelf.contentView).offset(-10);
//当前控件的Y轴中心点坐标和contentView的
make.centerY.equalTo(weakSelf.contentView);
}];
//设置当前空得水平垂直约束优先级最高
[_selectImagesetContentCompressionResistancePriority:UILayoutPriorityRequiredforAxis:UILayoutConstraintAxisHorizontal];
[_selectImagesetContentCompressionResistancePriority:UILayoutPriorityRequiredforAxis:UILayoutConstraintAxisVertical];
[_selectImagesetContentHuggingPriority:UILayoutPriorityRequiredforAxis:UILayoutConstraintAxisHorizontal];
[_selectImagesetContentHuggingPriority:UILayoutPriorityRequiredforAxis:UILayoutConstraintAxisVertical];
lessThanOrEqualTo 设置最小约束值
greaterThanOrEqualTo 设置最大约束值