autolayout UIImageView 根据 UILabel的宽度变换位置
仅个人学习笔记,大牛勿喷
代码写法 使用Masonry
1 //昵称 2 3 _nameLableView = [[UILabel alloc]init]; 4 5 [_nameLableView setTextColor:RGB(78, 164, 232)]; 6 7 _nameLableView.font=[UIFont systemFontOfSize:14]; 8 9 //_nameLableView.backgroundColor = [UIColor grayColor]; 10 11 [_nameLableView setText:@"Tom"]; 12 13 [_souceView addSubview:_nameLableView]; 14 15 //性别图标 16 _sexImageView = [[UIImageView alloc]init]; 17 18 [_sexImageView setImage:[UIImage imageNamed:@"woman_icon"]]; 19 20 [_souceView addSubview:_sexImageView]; 21 22 [_nameLableView mas_makeConstraints:^(MASConstraintMaker *make) { 23 make.top.equalTo(_nameLableView.superview.mas_top).with.offset(15); 24 make.left.equalTo(_headButtonView.mas_right).with.offset(10); 25 //make.right.equalTo(_sexImageView.mas_left).with.offset(5); 26 27 //make.height.mas_equalTo(16); 28 make.width.mas_lessThanOrEqualTo(ScreenWidth-100); 29 }]; 30 31 [_sexImageView mas_makeConstraints:^(MASConstraintMaker *make) { 32 make.top.equalTo(_sexImageView.superview.mas_top).with.offset(17); 33 make.left.equalTo(_nameLableView.mas_right).with.offset(5); 34 35 36 make.width.mas_equalTo(18); 37 make.height.mas_equalTo(13); 38 }];
UIStoryBoard写法
图片来源 CocoaChina 用户:kiushuo