123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- //
- // XYSetupTableViewCell.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2019/12/30.
- // Copyright © 2019 翟玉磊. All rights reserved.
- //
- #import "XYSetupTableViewCell.h"
- #import "XYSetupCellModel.h"
- @interface XYSetupTableViewCell ()
- @property (nonatomic, readwrite, strong) UILabel *titleLabel;
- @property (nonatomic, readwrite, strong) UILabel *disLabel;
- @property (nonatomic, readwrite, strong) UIImageView *moreImageView;
- @property (nonatomic, readwrite, strong) UIView *lineView;
- @end
- @implementation XYSetupTableViewCell
- #pragma mark - Public Method
- + (instancetype)cellWithTableView:(UITableView *)tableView {
- static NSString * const cellId = @"XYSetupTableViewCell";
- XYSetupTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
- if (!cell) {
- cell = [[XYSetupTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- return cell;
- }
- - (void)configureModel:(XYSetupCellModel *)model {
- self.titleLabel.text = model.title;
- self.disLabel.text = model.disStr;
- self.moreImageView.hidden = !model.isShowMore;
- self.switchView.hidden = !model.isShowSwitch;
- self.lineView.hidden = !model.isShowBottomLine;
- self.switchView.on = model.switchStatus;
- }
- #pragma mark - 初始化
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
-
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
- // 初始化
- [self _setup];
-
- // 创建自控制器
- [self _setupSubViews];
-
- // 布局子控件
- [self _makeSubViewsConstraints];
- }
- return self;
- }
- #pragma mark - 事件处理Or辅助方法
- #pragma mark - Private Method
- - (void)_setup{
- self.backgroundColor = UIColor.whiteColor;
- }
- #pragma mark - 创建子控件
- - (void)_setupSubViews{
- [self.contentView addSubview:self.titleLabel];
- [self.contentView addSubview:self.disLabel];
- [self.contentView addSubview:self.moreImageView];
- [self.contentView addSubview:self.switchView];
- [self.contentView addSubview:self.lineView];
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraints{
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(SPACING_EDGE);
- make.centerY.equalTo(self.contentView);
- }];
- [self.disLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView.mas_right).offset(-40);
- make.centerY.equalTo(self.contentView);
- }];
- [self.moreImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView).offset(-SPACING_EDGE);
- make.centerY.equalTo(self.contentView);
- make.width.equalTo(@6.0f);
- make.height.equalTo(@10.0f);
- }];
- [self.switchView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView).offset(-SPACING_EDGE);
- make.centerY.equalTo(self.contentView);
- make.width.equalTo(@48.0f);
- make.height.equalTo(@26.0f);
- }];
- [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.right.equalTo(self.contentView);
- make.height.equalTo(@0.3f);
- }];
- }
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font(14)];
- }
- return _titleLabel;
- }
- - (UILabel *)disLabel {
- if (!_disLabel) {
- _disLabel = [UILabel createLabelTextColor:ColorFromHexStringWithAlpha(@"#959598", 1) fount:Font(14)];
- }
- return _disLabel;
- }
- - (UIImageView *)moreImageView {
- if (!_moreImageView) {
- _moreImageView = [UIImageView new];
- _moreImageView.image = arrowMore();
- }
- return _moreImageView;
- }
- - (UISwitch *)switchView {
- if (!_switchView) {
- _switchView = [[UISwitch alloc] init];
- _switchView.on = NO;
- _switchView.onImage = ImageNamed(@"icon_switch_active");
- _switchView.offImage = ImageNamed(@"icon_switch_default");
- _switchView.onTintColor = Switch_Select_Color;
- }
- return _switchView;
- }
- - (UIView *)lineView {
- if (!_lineView) {
- _lineView = [UIView new];;
- _lineView.backgroundColor = Color_line;
- }
- return _lineView;
- }
- @end
|