介紹:Masonry是一個(gè)輕量級的布局框架 擁有自己的描述語法 采用更優(yōu)雅的鏈?zhǔn)秸Z法封裝自動布局 簡潔明了 并具有高可讀性 而且同時(shí)支持 iOS 和 Max OS X祟印。
送上源碼地址:https://github.com/Masonry/Masonry
Masonry與NSLayoutAttrubute的對照表如下
通過一些簡單的實(shí)例來簡單介紹如何輕松愉快的使用Masonry:
效果圖:
當(dāng)然有新添加增加約束械念,也有修改和重設(shè)約束兔跌。
//這個(gè)是修改約束
- (void)updateConstraints {? ? [self.growingButtonmas_updateConstraints:^(MASConstraintMaker *make) {? ? ? ? make.center.equalTo(self);? ? ? ? make.width.equalTo(@(self.buttonSize.width)).priorityLow();? ? ? ? make.height.equalTo(@(self.buttonSize.height)).priorityLow();? ? ? ? make.width.lessThanOrEqualTo(self);? ? ? ? make.height.lessThanOrEqualTo(self);? ? }];//according to apple super should be called at end of method[superupdateConstraints];}
//從新設(shè)置約束
[self.buttonmas_remakeConstraints:^(MASConstraintMaker *make) {? ? ? ? make.size.equalTo(self.buttonSize);if(topLeft) {? ? ? ? ? ? make.top.and.left.offset(10);? ? ? ? }else{? ? ? ? ? ? make.bottom.and.right.offset(-10);? ? ? ? }? ? }];