Files
yinmeng-ios/xplan-ios/Main/Room/View/CandyTree/View/Cell/XPCandyTreeMoreRuleCell.m
2023-03-10 19:06:13 +08:00

207 lines
6.1 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// XPCandyTreeMoreRuleCell.m
// xplan-ios
//
// Created by GreenLand on 2022/4/29.
//
#import "XPCandyTreeMoreRuleCell.h"
///Third
#import <Masonry/Masonry.h>
#import "ThemeColor.h"
#import "XCHUDTool.h"
#import "CandyTreeMoreItemModel.h"
#import "XPSwitch.h"
@interface XPCandyTreeMoreRuleCell ()
///标题
@property (nonatomic,strong) UILabel *titleLabel;
///容器
@property (nonatomic,strong) UIStackView *stackView;
///开关
@property (nonatomic,strong) UIView *switchView;
@property (nonatomic, strong) XPSwitch *switchButton;
@property (nonatomic,strong) UIButton *disableButton;
///箭头
@property (nonatomic,strong) UIImageView *arrowImageView;
///分割线
@property (nonatomic,strong) UIView *lineView;
@end
@implementation XPCandyTreeMoreRuleCell
- (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 = [UIColor clearColor];
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];
[self.switchView addSubview:self.switchButton];
[self.switchView addSubview:self.disableButton];
}
- (void)initSubViewConstraints {
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.contentView).offset(-7);
make.left.mas_equalTo(16);
}];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.titleLabel);
make.right.mas_equalTo(self.contentView).offset(-15);
}];
[self.switchView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(30);
make.width.mas_equalTo(30);
}];
[self.switchButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.centerY.mas_equalTo(self.switchView);
make.size.mas_equalTo(CGSizeMake(38, 18));
}];
[self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(5.5, 10));
}];
[self.disableButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.switchButton);
}];
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.contentView).inset(15);
make.bottom.mas_equalTo(self.contentView);
make.height.mas_equalTo(0.5);
}];
}
- (void)switchDidChange:(UISwitch *)switchButton {
if (switchButton.on) {
_switchButton.thumbTintColor = [ThemeColor colorWithHexString:@"#f8cbff"];
} else {
_switchButton.thumbTintColor = [ThemeColor colorWithHexString:@"#6e31c8"];
}
if (self.itemModel.switchEnable && self.delegate && [self.delegate respondsToSelector:@selector(xPCandyTreeMoreRuleCell:switchChange:)]) {
[self.delegate xPCandyTreeMoreRuleCell:self switchChange:switchButton];
}
}
- (void)disableButtonAction:(UIButton *)sender {
if (!self.itemModel.switchEnable && self.sendMessageSwitchLevel > 0) {
[XCHUDTool showErrorWithMessage:[NSString stringWithFormat:@"财富值达到%ld级可用快去升级吧~", self.sendMessageSwitchLevel]];
}
}
#pragma mark - Getters And Setters
- (void)setItemModel:(CandyTreeMoreItemModel *)itemModel {
_itemModel = itemModel;
if (_itemModel) {
self.titleLabel.text = _itemModel.title;
if (_itemModel.type == CandyTreeMoreItemType_Switch) {
self.switchView.hidden = NO;
self.arrowImageView.hidden = YES;
self.switchButton.on = _itemModel.switchState;
if (_itemModel.switchEnable) {
self.disableButton.hidden = YES;
} else {
self.switchButton.on = NO;
self.disableButton.hidden = NO;
}
if (_switchButton.on) {
_switchButton.thumbTintColor = [ThemeColor colorWithHexString:@"#f8cbff"];
} else {
_switchButton.thumbTintColor = [ThemeColor colorWithHexString:@"#6e31c8"];
}
} else {
self.switchView.hidden = YES;
self.arrowImageView.hidden = NO;
}
}
}
- (XPSwitch *)switchButton {
if (!_switchButton) {
_switchButton = [[XPSwitch alloc] initWithFrame:CGRectMake(0, 0, 38, 18)];
_switchButton.backgroundColor = [UIColor clearColor];
_switchButton.onTintColor = [ThemeColor colorWithHexString:@"#490dad"];
_switchButton.tintColor = [ThemeColor colorWithHexString:@"#490dad"];
_switchButton.thumbTintColor = [ThemeColor colorWithHexString:@"#6e31c8"];
_switchButton.shadow = NO;
[_switchButton addTarget:self action:@selector(switchDidChange:) forControlEvents:UIControlEventValueChanged];
}
return _switchButton;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:11];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.textColor = [ThemeColor colorWithHexString:@"#F8CBFF"];
_titleLabel.backgroundColor = [UIColor clearColor];
}
return _titleLabel;
}
- (UIButton *)disableButton {
if (!_disableButton) {
_disableButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_disableButton addTarget:self action:@selector(disableButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _disableButton;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentCenter;
_stackView.spacing = 0;
}
return _stackView;
}
- (UIView *)switchView {
if (!_switchView) {
_switchView = [[UIView alloc] init];
_switchView.backgroundColor = [UIColor clearColor];
}
return _switchView;
}
- (UIImageView *)arrowImageView {
if (!_arrowImageView) {
_arrowImageView = [[UIImageView alloc] init];
_arrowImageView.userInteractionEnabled = YES;
_arrowImageView.image = [UIImage imageNamed:@"candy_tree_arrow"];
}
return _arrowImageView;
}
- (UIView *)lineView {
if (!_lineView) {
_lineView = [[UIView alloc] init];
_lineView.backgroundColor = UIColorRGBAlpha(0xEDEDED, 0.2);
}
return _lineView;
}
@end