Masonry 使用介紹


1、Masonry其實就是對系統的Autolayout 進行了封裝、大大的提高了開發效率 

2、Masonry用到的是鏈式編程思想

#import "ViewController.h"
#import <Masonry.h>
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *red = [[UIView alloc] init];
    red.backgroundColor = [UIColor redColor];
    [self.view addSubview:red];
    //masonry 內部默認設置了 translatesAutoresizingMaskIntoConstraints
    red.translatesAutoresizingMaskIntoConstraints = NO;
    [red mas_makeConstraints:^(MASConstraintMaker *make) {
// 以下幾種寫法都一樣        1。make.left.mas_equalTo(self.view.mas_left).multipliedBy(1.0).with.offset(20);

//       2 make.left.mas_equalTo(self.view.mas_left).offset(20);
//       3 make.left.mas_equalTo(self.view).offset(20);
//      4  make.left.offset(20);
//       5 make.left.and.top.offset(20);
//        make.left.top.offset(20); and可以省略
//        make.right.mas_equalTo(self.view).offset(-20);
//        make.top.mas_equalTo(self.view).offset(20);
//        make.bottom.mas_equalTo(self.view).offset(-20);

        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(20, 20, 20, 20));
    }];
    //更新約束
    [red mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.offset(-100);
    }];
    //刪除之前的約束 重新設置約束
    [red mas_remakeConstraints:^(MASConstraintMaker *make) {
        
    }];
    // Do any additional setup after loading the view.
}

@end

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM