CNMessgeNoteCell.m 2.34 KB
//
//  CNMeaageNoteCell.m
//  CNLiveCMineModule
//
//  Created by iOS on 2022/12/7.
//

#import "CNMessgeNoteCell.h"
@interface CNMessgeNoteCell ()
@property (nonatomic, strong)UIView *bgView;
@property (nonatomic, strong)UILabel *titleLabel;
@property (nonatomic, strong)UISwitch *switchBtn;

@end

@implementation CNMessgeNoteCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = [UIColor clearColor];
        self.backgroundColor = UIColorClear;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.bgView];
        [self.bgView addSubview:self.titleLabel];
        [self.bgView addSubview:self.switchBtn];
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
            make.top.equalTo(self).offset(10);
        }];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.bgView);
            make.left.equalTo(self).offset(16);
        }];
        [self.switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.bgView);
            make.right.equalTo(self).offset(-8);
        }];
    }
    return self;
}
- (void)switchValueChanged:(UISwitch *)sender{
    self.model.state = sender.isOn;
    if (self.changeSwitchBlock) {
        self.changeSwitchBlock(self.model);
    }
}
#pragma mark - Setting
- (void)setModel:(CNMessageNoteModel *)model{
    _model = model;
    self.titleLabel.text = model.title;
    [self.switchBtn setOn:model.state];
}
#pragma mark - Getting
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = UIColorWhite;
    }
    return _bgView;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = UIColorHex(#282828);
        _titleLabel.font = UIFontMake(16);
    }
    return _titleLabel;
}
- (UISwitch *)switchBtn{
    if (!_switchBtn) {
        _switchBtn = [[UISwitch alloc] init];
        [_switchBtn addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
    }
    return _switchBtn;
}
@end