gliubc
6/14/2018 - 2:24 AM

TableViewCell

TableViewCell

@implementation SelectCategoryTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        UILabel *label = [UILabel new];
        label.textColor = HEXCOLOR(0x333333);
        label.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.centerY.equalTo(self.contentView);
        }];
        self.label = label;

        UIView *indicator = [UIView new];
        [self.contentView addSubview:indicator];
        [indicator mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView);
            make.width.equalTo(@2);
            make.height.equalTo(@22);
            make.centerY.equalTo(self.contentView);
        }];
        self.indicator = indicator;
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    if (selected) {
        self.contentView.backgroundColor = HEXCOLOR(0xF4F5F6);
        self.label.textColor = HEXCOLOR(0xFA4544);
        self.indicator.backgroundColor = HEXCOLOR(0xFA4544);
    } else {
        self.contentView.backgroundColor = [UIColor clearColor];
        self.label.textColor = HEXCOLOR(0x333333);
        self.indicator.backgroundColor = [UIColor clearColor];
    }
}
@end

@interface SelectCategoryTableViewCell : UITableViewCell

@property (strong, nonatomic) UILabel *label;
@property (strong, nonatomic) UIView *indicator;

@end