// // TFLanguageSetCell.m // TFReader // // Created by 谢腾飞 on 2020/12/14. // Copyright © 2020 xtfei_2011@126.com. All rights reserved. // #import "TFLanguageSetCell.h" #import "NSObject+Observer.h" #import "TFLanguageSetModel.h" @interface TFLanguageSetCell () { __weak UIImageView *_selecteImageView; } @end @implementation TFLanguageSetCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.selectionStyle = UITableViewCellSelectionStyleNone; [self createSubviews]; } return self; } - (void)createSubviews { self.contentView.backgroundColor = [UIColor whiteColor]; UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.textColor = kBlackColor; titleLabel.font = kFont16; [self.contentView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(kHalfMargin); make.left.equalTo(self.contentView).offset(kMoreHalfMargin); }]; UILabel *subtitleLabel = [[UILabel alloc] init]; subtitleLabel.textColor = kGrayTextColor; subtitleLabel.font = kFont12; [self.contentView addSubview:subtitleLabel]; [subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(titleLabel.mas_bottom).offset(kQuarterMargin); make.left.right.equalTo(titleLabel); make.height.mas_equalTo(kMoreHalfMargin); }]; UIImageView *selectedImageView = [[UIImageView alloc] init]; _selecteImageView = selectedImageView; selectedImageView.hidden = YES; selectedImageView.image = [[UIImage imageNamed:@"public_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; selectedImageView.tintColor = kMainColor; [self.contentView addSubview:selectedImageView]; [selectedImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.contentView); make.right.equalTo(self.contentView).offset(-kMoreHalfMargin); make.width.height.mas_equalTo(22.0); }]; [titleLabel mas_updateConstraints:^(MASConstraintMaker *make) { make.right.equalTo(selectedImageView.mas_left).offset(-kHalfMargin); }]; UIView *lineView = [[UIView alloc] init]; self.lineView = lineView; lineView.backgroundColor = kGrayLineColor; [self.contentView addSubview:lineView]; [lineView mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(kCellLineHeight); make.left.equalTo(titleLabel); make.right.equalTo(selectedImageView); make.bottom.equalTo(self.contentView); make.top.equalTo(subtitleLabel.mas_bottom).offset(kHalfMargin).priorityLow(); }]; [self addObserver:KEY_PATH(self, languageModel) complete:^(id _Nonnull obj, id _Nullable oldVal, TFLanguageSetModel * _Nullable newVal) { titleLabel.text = newVal.title ?: @""; subtitleLabel.text = newVal.subtitle ?: @""; }]; } - (void)set_selected:(BOOL)selected { _selecteImageView.hidden = !selected; } @end