// mas_equalTo 這個方法會對參數進行包裝處理 equalTo不會 mas_equalTo功能強於 -> equalTo 約束類型: 1.width/height/size 2.left/right/top/bottom/leading/trailing 3.center/centerX/centerY 4.edges UIView *blueView = [[UIView alloc] init]; blueView.backgroundColor = [UIColor blueColor]; [self.view addSubview:blueView]; //尺寸限制:100x100 //位置:粘着服控件右下角,間距是20 //這個方法只會添加新的約束 [blueView mas_makeConstraints:^(MASConstraintMaker *make) { }]; //這個方法將之前的全部約束刪掉,添加新約束 [blueView mas_remakeConstraints:^(MASConstraintMaker *make) { }]; //這個方法將會覆蓋之前的某些待定的約束 [blueView mas_updateConstraints:^(MASConstraintMaker *make) { }]; //普通寫法: make.width.equalTo(@100); make.height.equalTo(@100); make.right.equalTo(self.view.right).offset(-20); make.bottom.equalTo(self.view.bottom).offset(-20); //簡潔寫法: mas_equalTo 優先使用 make.width.mas_equalTo(100);//傳入任何基本數據類型,由mas自動轉化 make.height.mas_equalTo(100); make.right.mas_equalTo(self.view).offset(-20); make.bottom.mas_equalTo(self.view).offset(-20); //其餘寫法: //大小 make.size.mas_equalTo(100); make.size.mas_equalTo(self.view).multipliedBy(0.5).offset(-5); //中心點 make.centerX.mas_equalTo(self.view); make.centerY.mas_equalTo(self.view); make.center.mas_equalTo(self.view); //邊距 第一種寫法: make.left.mas_equalTo(self.view).offset(50); make.right.mas_equalTo(self.view).offset(-50); make.top.mas_equalTo(self.view).offset(50); make.bottom.mas_equalTo(self.view).offset(-50); 第二種寫法: make.left.top.offset(50); make.right.bottom.offset(-50); 第三種寫法: make.edges.mas_equalTo(self.view).insets(UIEdgeInsetsMake(50, 50, 50, 50)); make.edges.insets(UIEdgeInsetsZero);