02-Masory框架

框架地址:

https://github.com/SnapKit/Masonry

Masory介紹:

1.默認(rèn)情況下:
mas_equalTo有自動(dòng)包裝功能,比如自動(dòng)將20包裝為@20
equalTo沒(méi)有自動(dòng)包裝功能

2.如果添加了下面的宏,那么mas_equalTo和equalTo就沒(méi)有區(qū)別,注意:這個(gè)宏一定要添加到#import "Masonry.h"前面

#define MAS_SHORTHAND_GLOBALS

3.默認(rèn)情況下:

  • width是make對(duì)象的一個(gè)屬性,用來(lái)添加寬度約束用的,表示對(duì)寬度進(jìn)行約束
  • mas_width是一個(gè)屬性值,用來(lái)當(dāng)做equalTo的參數(shù),表示某個(gè)控件的寬度屬性
  • 如果添加了下面的宏,mas_width也可以寫成width
#define MAS_SHORTHAND

mas_height、mas_centerX以此類推

4.示范代碼:


#import "ViewController.h"
//define this constant if you want to use Masonry without
 the 'mas_' prefix
#define MAS_SHORTHAND
//define this constant if you want to enable auto-boxing
 for default syntax
#define MAS_SHORTHAND_GLOBALS
#import "Masonry.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // 1.創(chuàng)建藍(lán)色的view添加到控制器中
    UIView *blueView = [[UIView alloc] init];
    blueView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:blueView];
    
    // 2.創(chuàng)建紅色的view添加到控制器中
    UIView *redView = [[UIView alloc] init];
    redView.backgroundColor = [UIColor redColor];
    [self.view addSubview:redView];
    
    // 3.添加新的約束
    [blueView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.left).offset(30);
        make.bottom.equalTo(self.view.bottom).offset(-30);
        make.right.equalTo(redView.left).offset(-30);
        make.width.equalTo(redView.width);
//        make.height.equalTo(50);
    }];
    
    [redView makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.right).offset(-30);
        make.top.equalTo(blueView.top);
        make.bottom.equalTo(blueView.bottom);
    }];
    
    // 4.更新約束
    [blueView updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(80);
    }];
    
    // 5.刪除之前所有的約束,重新添加約束
//    [blueView remakeConstraints:^(MASConstraintMaker *make) {
//        
//    }];

5.以下方法都僅僅是為了提高可讀性,可有可無(wú)

- (MASConstraint *)with {    
          return self;
}
- (MASConstraint *)and {    
          return self;
}

  • Posted by *** singerYoung ***
  • 聯(lián)系作者 簡(jiǎn)書·singerYoung 新浪微博·小小羊run
  • 原創(chuàng)文章,版權(quán)聲明:自由轉(zhuǎn)載-非商用-非衍生-保持署名
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容