Files
peko-ios/YuMi/Modules/YMMine/View/Cell/XPMineSettingTableViewCell.m
2025-03-21 16:19:07 +08:00

137 lines
4.0 KiB
Objective-C

//
// YMMineSettingTableViewCell.m
// YUMI
//
// Created by YUMI on 2021/9/17.
//
#import "XPMineSettingTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "DJDKMIMOMColor.h"
///Model
#import "XPMineSettingItemModel.h"
@interface XPMineSettingTableViewCell ()
///容器
@property (nonatomic,strong) UIStackView *stackView;
///标题
@property (nonatomic,strong) UILabel *titleLabel;
///副标题
@property (nonatomic,strong) UILabel *subTitleLabel;
///箭头
@property (nonatomic,strong) UIImageView *arrowImageView;
@property(nonatomic, strong) UIView *line;
@end
@implementation XPMineSettingTableViewCell
- (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.contentView.backgroundColor = UIColorFromRGB(0xf2f3f7);
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.stackView];
[self.stackView addArrangedSubview:self.titleLabel];
[self.stackView addArrangedSubview:self.subTitleLabel];
[self.stackView addArrangedSubview:self.arrowImageView];
[self.contentView addSubview:self.line];
}
- (void)initSubViewConstraints {
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.contentView).inset(15);
make.top.bottom.mas_equalTo(self.contentView);
}];
[self.line mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.contentView).inset(15);
make.height.mas_equalTo(0.5);
make.bottom.mas_equalTo(self.contentView);
}];
}
- (void)setTopCorner:(BOOL)setTop bottomCorner:(BOOL)setBottom {
self.line.hidden = NO;
if (setTop) {
[self setCornerRadius:8 corners:kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner];
} else if (setBottom) {
self.line.hidden = YES;
[self setCornerRadius:8 corners:kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner];
} else {
[self setCornerRadius:0 corners:kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner | kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner];
}
}
#pragma mark - Getters And Setters
- (void)setItemModel:(XPMineSettingItemModel *)itemModel {
_itemModel = itemModel;
self.titleLabel.text = _itemModel.title;
self.subTitleLabel.text = _itemModel.subTitle;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentCenter;
_stackView.spacing = 10;
}
return _stackView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = kFontRegular(14);
_titleLabel.textColor = UIColorFromRGB(0x313131);
[_titleLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
}
return _titleLabel;
}
- (UILabel *)subTitleLabel {
if (!_subTitleLabel) {
_subTitleLabel = [[UILabel alloc] init];
_subTitleLabel.font = kFontRegular(14);
_subTitleLabel.textColor = UIColorFromRGB(0x7b7b7d);
_subTitleLabel.textAlignment = NSTextAlignmentRight;
}
return _subTitleLabel;
}
- (UIImageView *)arrowImageView {
if (!_arrowImageView) {
_arrowImageView = [[UIImageView alloc] init];
_arrowImageView.userInteractionEnabled = YES;
_arrowImageView.image = [[UIImage imageNamed:@"mine_item_arrow"]ms_SetImageForRTL];
[_arrowImageView setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
[_arrowImageView setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
}
return _arrowImageView;
}
- (UIView *)line {
if (!_line) {
_line = [[UIView alloc] init];
_line.backgroundColor = UIColorFromRGB(0xe4e4e4);
}
return _line;
}
@end