Files
yinmeng-ios/xplan-ios/Main/Mine/View/Cell/XPMineMenuTableViewCell.m

139 lines
3.9 KiB
Objective-C

//
// XPMineMenuTableViewCell.m
// xplan-ios
//
// Created by 冯硕 on 2021/9/16.
//
#import "XPMineMenuTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor.h"
#import "XPMacro.h"
///Model
#import "XPMineItemModel.h"
@interface XPMineMenuTableViewCell ()
///背景
@property (nonatomic,strong) UIView * backView;
///
@property (nonatomic,strong) UIStackView *stackView;
///显示图片
@property (nonatomic,strong) UIImageView *logoImageView;
///显示名字
@property (nonatomic,strong) UILabel *titleLabel;
///箭头
@property (nonatomic,strong) UIButton *arrowButton;
@end
@implementation XPMineMenuTableViewCell
- (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.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.backView];
[self.backView addSubview:self.stackView];
[self.stackView addArrangedSubview:self.logoImageView];
[self.stackView addArrangedSubview:self.titleLabel];
[self.stackView addArrangedSubview:self.arrowButton];
}
- (void)initSubViewConstraints {
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.mas_equalTo(self.contentView);
make.right.left.mas_equalTo(self.contentView).inset(15);
}];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.mas_equalTo(self.backView);
make.right.left.mas_equalTo(self.backView).inset(15);
}];
[self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(24, 24));
}];
}
- (void)applyRoundCorners:(UIRectCorner)corners radius:(CGFloat)radius
{
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, KScreenWidth - 30 , 53) byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.path = path.CGPath;
self.backView.layer.mask = maskLayer;
}
#pragma mark - Getters And Setters
- (void)setItemModel:(XPMineItemModel *)itemModel {
_itemModel = itemModel;
if (_itemModel) {
self.logoImageView.image = [UIImage imageNamed:_itemModel.itemImageName];
self.titleLabel.text = _itemModel.itemName;
if (itemModel.cornerType) {
[self applyRoundCorners:itemModel.cornerType radius:10];
}
}
}
- (UIView *)backView {
if (!_backView) {
_backView = [[UIView alloc] init];
_backView.backgroundColor = [ThemeColor appCellBackgroundColor];;
}
return _backView;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentCenter;
_stackView.spacing = 10;
_stackView.backgroundColor = [ThemeColor appCellBackgroundColor];
}
return _stackView;
}
- (UIImageView *)logoImageView {
if (!_logoImageView) {
_logoImageView = [[UIImageView alloc] init];
_logoImageView.userInteractionEnabled = YES;
}
return _logoImageView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:13];
_titleLabel.textColor = [ThemeColor secondTextColor];
}
return _titleLabel;
}
- (UIButton *)arrowButton {
if (!_arrowButton) {
_arrowButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_arrowButton setImage:[UIImage imageNamed:@"mine_item_arrow"] forState:UIControlStateNormal];
[_arrowButton setImage:[UIImage imageNamed:@"mine_item_arrow"] forState:UIControlStateSelected];
[_arrowButton setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
}
return _arrowButton;
}
@end