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

167 lines
4.6 KiB
Objective-C

//
// SessionSettingTableViewCell.m
// YUMI
//
// Created by YUMI on 2023/1/18.
//
#import "SessionSettingTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "DJDKMIMOMColor.h"
///Model
#import "SessionSettingModel.h"
@interface SessionSettingTableViewCell ()
///显示标题
@property (nonatomic,strong) UILabel *titleLabel;
///开关盒箭头的容器
@property (nonatomic,strong) UIStackView *stackView;
///开关
@property (nonatomic,strong) UISwitch *switchView;
///箭头
@property (nonatomic,strong) UIImageView *arrowImageView;
///分割线
@property (nonatomic,strong) UIView *lineView;
@end
@implementation SessionSettingTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor = [DJDKMIMOMColor appCellBackgroundColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.stackView];
[self.contentView addSubview:self.lineView];
[self.stackView addArrangedSubview:self.switchView];
[self.stackView addArrangedSubview:self.arrowImageView];
}
- (void)initSubViewConstraints {
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.contentView).offset(15);
make.centerY.mas_equalTo(self.contentView);
}];
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.contentView);
make.height.mas_equalTo(0.5);
make.leading.trailing.mas_equalTo(self.contentView).inset(15);
}];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(self.contentView).offset(-15);
make.centerY.mas_equalTo(self.contentView);
}];
[self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(5.5, 10));
}];
}
#pragma mark - Event Response
- (void)switchDidChange:(UISwitch *)switchOn {
if (self.delegate && [self.delegate respondsToSelector:@selector(sessionSettingTableViewCell:switchState:)]) {
[self.delegate sessionSettingTableViewCell:self.chatItem switchState:switchOn];
}
}
#pragma mark - Getters And Setters
- (void)setChatItem:(SessionSettingModel *)chatItem{
_chatItem = chatItem;
if ( _chatItem) {
self.titleLabel.text = _chatItem.title;
switch (_chatItem.settingType) {
case SessionSettingType_Top:
{
self.arrowImageView.hidden = YES;
self.switchView.hidden = NO;
self.switchView.on = _chatItem.state;
}
break;
case SessionSettingType_black:
{
self.arrowImageView.hidden = YES;
self.switchView.hidden = NO;
self.switchView.on = _chatItem.state;
}
break;
case SessionSettingType_report:
{
self.arrowImageView.hidden = NO;
self.switchView.hidden = YES;
}
break;
default:
break;
}
}
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:14];
_titleLabel.textColor = [DJDKMIMOMColor mainTextColor];
}
return _titleLabel;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentCenter;
_stackView.spacing = 10;
}
return _stackView;
}
- (UISwitch *)switchView {
if (!_switchView) {
_switchView = [[UISwitch alloc] init];
_switchView.onTintColor = [DJDKMIMOMColor appEmphasizeColor];
_switchView.tintColor = [DJDKMIMOMColor appMainColor];
_switchView.backgroundColor = [UIColor clearColor];
[_switchView addTarget:self action:@selector(switchDidChange:) forControlEvents:UIControlEventValueChanged];
}
return _switchView;
}
- (UIImageView *)arrowImageView {
if (!_arrowImageView) {
_arrowImageView = [[UIImageView alloc] init];
_arrowImageView.userInteractionEnabled = YES;
_arrowImageView.image = [UIImage imageNamed:@"room_setting_arrow"];
}
return _arrowImageView;
}
- (UIView *)lineView {
if (!_lineView) {
_lineView = [[UIView alloc] init];
_lineView.backgroundColor = [DJDKMIMOMColor actionSeparatorColor];
}
return _lineView;
}
@end