iOS Masonry使用
1、控件在cell上高度居中
自定义cell的.m文件
#import "YDTaoXiaoDianAddressCell.h"
@interface YDTaoXiaoDianAddressCell()
@end
@implementation YDTaoXiaoDianAddressCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
-(UIButton *)mapBtn{
if (!_mapBtn) {
_mapBtn=[UIButton buttonWithType:UIButtonTypeCustom];
[self addSubview:_mapBtn];
[_mapBtn setImage:[UIImage imageNamed:@"地图icon"] forState:UIControlStateNormal];
}
return _mapBtn;
}
-(UIButton *)phoneBtn{
if (!_phoneBtn) {
_phoneBtn=[UIButton buttonWithType:UIButtonTypeCustom];
[self addSubview:_phoneBtn];
[_phoneBtn setImage:[UIImage imageNamed:@"电话icon 拷贝 3"] forState:UIControlStateNormal];
}
return _phoneBtn;
}
#pragma mark-Masonry布局
-(void)drawRect:(CGRect)rect{
[self.mapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self);
make.width.equalTo(@40);
make.height.equalTo(@40);
make.right.equalTo(self.phoneBtn.mas_left).offset(-20);
}];
[self.phoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mapBtn);
make.width.equalTo(@40);
make.height.equalTo(@40);
make.right.equalTo(self.contentView.mas_right).offset(-10);
}];
[self layoutIfNeeded];
}
2、Masonry布局两个相邻的且有相互约束的控件,他们布局的先后顺序无所谓
本文标题:iOS Masonry使用
本文链接:https://www.haomeiwen.com/subject/ggyhkqtx.html
网友评论