1.Content Compression Resistance 百度翻譯(內容壓縮抗力)ui
2.Content Hugging 百度翻譯(內容擁抱) atom
1 #import "ViewController.h" 2 #import "Masonry.h" 3 4 @interface ViewController () 5 6 @property(nonatomic,strong) UILabel * labelOne; 7 @property(nonatomic,strong) UILabel * labelTwo; 8 9 @end 10 11 @implementation ViewController 12 13 14 - (void)initUI 15 { 16 [self.view addSubview:self.labelOne]; 17 [self.labelOne mas_makeConstraints:^(MASConstraintMaker *make) { 18 make.left.equalTo(self.view.mas_left).with.offset(20); 19 make.top.equalTo(self.view.mas_top).with.offset(20); 20 }]; 21 22 [self.view addSubview:self.labelTwo]; 23 [self.labelTwo mas_makeConstraints:^(MASConstraintMaker *make) { 24 make.left.equalTo(_labelOne.mas_right); 25 make.right.equalTo(self.view.mas_right); 26 make.top.equalTo(self.view.mas_top).with.offset(20); 27 make.height.equalTo(_labelOne); 28 }]; 29 30 [self.labelOne setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal]; 31 /**參數一:(UILayoutPriority) 32 UILayoutPriorityRequired 33 UILayoutPriorityDefaultHigh 34 UILayoutPriorityDefaultLow 35 UILayoutPriorityFittingSizeLevel 36 */ 37 38 /**參數二:(UILayoutConstraintAxis) 39 UILayoutConstraintAxisHorizontal 40 UILayoutConstraintAxisVertical 41 */ 42 [self.labelTwo setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal]; 43 } 44 - (void)viewDidLoad { 45 [super viewDidLoad]; 46 47 [self initUI]; 48 } 49 50 - (UILabel *)labelOne 51 { 52 if (!_labelOne) { 53 self.labelOne = [[UILabel alloc] init]; 54 self.labelOne.text = @"這是labelOne"; 55 self.labelOne.backgroundColor = [UIColor redColor]; 56 } 57 return _labelOne; 58 } 59 60 - (UILabel *)labelTwo 61 { 62 if (!_labelTwo) { 63 self.labelTwo = [[UILabel alloc] init]; 64 self.labelTwo.text = @"這是labelTwo"; 65 self.labelTwo.backgroundColor = [UIColor greenColor]; 66 } 67 return _labelTwo; 68 } 69 70 @end