Files
peko-ios/YuMi/Modules/YMMine/View/Cell/XPMineNotificationTableViewCell.m
2024-04-11 17:05:27 +08:00

107 lines
3.2 KiB
Objective-C

//
// YMMineNotificationTableViewCell.m
// YUMI
//
// Created by YUMI on 2021/9/17.
//
#import "XPMineNotificationTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "DJDKMIMOMColor.h"
///Model
#import "XPMineNotificationItemModel.h"
@interface XPMineNotificationTableViewCell ()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subtitleLabel;
@property (nonatomic, strong) UISwitch *selectSwitch;
@end
@implementation XPMineNotificationTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self initSubviews];
[self makeConstriants];
}
return self;
}
#pragma mark - event
- (void)switchDidTapped:(UISwitch *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineNotificationTableViewCell:switchStatus:)]) {
[self.delegate xPMineNotificationTableViewCell:self switchStatus:sender.on];
}
}
#pragma mark - private
- (void)initSubviews {
[self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.subtitleLabel];
[self.contentView addSubview:self.selectSwitch];
self.backgroundColor = [DJDKMIMOMColor appCellBackgroundColor];
}
- (void)makeConstriants {
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.contentView).offset(15);
make.top.mas_equalTo(14);
}];
[self.subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.contentView).inset(15);
make.trailing.mas_equalTo(self.contentView).inset(65);
make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(8);
}];
[self.selectSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(self.contentView).offset(-15);
make.centerY.mas_equalTo(self.contentView);
}];
}
#pragma mark - Getter && Setter
- (void)setItemModel:(XPMineNotificationItemModel *)itemModel {
_itemModel = itemModel;
self.titleLabel.text = _itemModel.title;
self.subtitleLabel.text = _itemModel.desc;
self.selectSwitch.on = _itemModel.notification;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:16];
_titleLabel.textColor = [DJDKMIMOMColor mainTextColor];
}
return _titleLabel;
}
- (UILabel *)subtitleLabel {
if (!_subtitleLabel) {
_subtitleLabel = [[UILabel alloc] init];
_subtitleLabel.font = [UIFont systemFontOfSize:12];
_subtitleLabel.textColor = [DJDKMIMOMColor secondTextColor];
_subtitleLabel.numberOfLines = 2;
}
return _subtitleLabel;
}
- (UISwitch *)selectSwitch {
if (_selectSwitch == nil) {
_selectSwitch = [[UISwitch alloc] init];
_selectSwitch.onTintColor = [DJDKMIMOMColor appMainColor];
_selectSwitch.tintColor = [DJDKMIMOMColor disableButtonColor];
_selectSwitch.backgroundColor = [UIColor clearColor];
_selectSwitch.layer.cornerRadius = CGRectGetHeight(_selectSwitch.frame)/2.0;
_selectSwitch.layer.masksToBounds = YES;
[_selectSwitch addTarget:self action:@selector(switchDidTapped:) forControlEvents:UIControlEventValueChanged];
}
return _selectSwitch;
}
@end