通过massonry实现自定义cell
初始化方法实现辅助视图:
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.accessoryType = 1;//右箭头
//让cell的分割线 去掉左边距
self.separatorInset = UIEdgeInsetsZero;
}
return self;
}
添加Label:
- (UILabel *)titleLb{
if (_titleLb == nil) {
_titleLb = [UILabel new];
[self.contentView addSubview:_titleLb];
[_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(0);
//注意, 这里用的点语法调用的iconIV. 因为懒加载的原因, 可以保证iconIV一定是初始化过的.!!!
make.left.equalTo(self.iconIV.mas_right).offset(12);
}];
}
return _titleLb;
}
添加视图:
- (UIImageView *)iconIV{
if (_iconIV == nil) {
_iconIV = [UIImageView new];
[self.contentView addSubview:_iconIV];
[_iconIV mas_makeConstraints:^(MASConstraintMaker *make) {
// make.size.equalTo(20);
make.left.equalTo(10);
make.centerY.equalTo(0);
}];
}
return _iconIV;
}
效果如下: