Files
peko-ios/YuMi/Modules/YMMine/View/XPMineItemTableViewCell.m

196 lines
6.2 KiB
Mathematica
Raw Normal View History

2023-07-06 16:54:13 +08:00
//
// YMMineItemTableViewCell.m
// YUMI
//
// Created by XY on 2023/2/20.
//
2023-07-14 18:50:55 +08:00
#import "XPMineItemTableViewCell.h"
#import "NetImageView.h"
2023-07-06 16:54:13 +08:00
#import <Masonry.h>
#import "DJDKMIMOMColor.h"
#import "UIView+Corner.h"
#import "YUMIMacroUitls.h"
2023-07-14 18:50:55 +08:00
#import "XPMineItemModel.h"
2023-07-06 16:54:13 +08:00
2023-07-14 18:50:55 +08:00
@interface XPMineItemTableViewCell()
2023-07-06 16:54:13 +08:00
2023-07-14 18:50:55 +08:00
///
2023-07-06 16:54:13 +08:00
@property (nonatomic, strong) UIView *containerView;
2023-07-14 18:50:55 +08:00
///
@property (nonatomic, strong) NetImageView *iconImageView;
///
2023-07-06 16:54:13 +08:00
@property (nonatomic, strong) UILabel *titleLabel;
2023-07-14 18:50:55 +08:00
///
@property (nonatomic, strong) UIImageView *arrowImageView;
/// 线
@property (nonatomic, strong) UIView *dashLineView;
2023-07-06 16:54:13 +08:00
@property (nonatomic, strong) CAShapeLayer *shapeLayer;
@end
2023-07-14 18:50:55 +08:00
@implementation XPMineItemTableViewCell
2023-07-06 16:54:13 +08:00
- (void)awakeFromNib {
[super awakeFromNib];
2023-07-14 18:50:55 +08:00
// Initialization code
2023-07-06 16:54:13 +08:00
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
2023-07-14 18:50:55 +08:00
// Configure the view for the selected state
2023-07-06 16:54:13 +08:00
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = UIColor.clearColor;
self.contentView.backgroundColor = UIColor.clearColor;
2023-07-14 18:50:55 +08:00
[self createUI];
2023-07-06 16:54:13 +08:00
}
return self;
}
2023-07-14 18:50:55 +08:00
- (void)createUI {
2023-07-06 16:54:13 +08:00
[self.contentView addSubview:self.containerView];
2023-07-14 18:50:55 +08:00
[self.containerView addSubview:self.iconImageView];
2023-07-06 16:54:13 +08:00
[self.containerView addSubview:self.titleLabel];
2023-07-14 18:50:55 +08:00
[self.containerView addSubview:self.arrowImageView];
[self.containerView addSubview:self.dashLineView];
2023-07-06 16:54:13 +08:00
[self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
2024-04-11 17:05:27 +08:00
make.leading.mas_equalTo(16);
make.trailing.mas_equalTo(-16);
2023-07-06 16:54:13 +08:00
make.top.bottom.mas_equalTo(0);
}];
2023-07-14 18:50:55 +08:00
[self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
2024-04-11 17:05:27 +08:00
make.leading.mas_equalTo(12);
2023-07-06 16:54:13 +08:00
make.centerY.mas_equalTo(self.containerView);
make.width.height.mas_equalTo(40);
}];
2023-07-14 18:50:55 +08:00
[self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
2024-04-11 17:05:27 +08:00
make.trailing.mas_equalTo(0);
2023-07-06 16:54:13 +08:00
make.width.mas_equalTo(40);
make.height.mas_equalTo(12);
make.centerY.mas_equalTo(self.containerView);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
2024-04-11 17:05:27 +08:00
make.leading.mas_equalTo(self.iconImageView.mas_trailing).offset(2);
make.trailing.mas_equalTo(self.arrowImageView.mas_leading).offset(-2);
2023-07-06 16:54:13 +08:00
make.centerY.mas_equalTo(self.containerView);
}];
2023-07-14 18:50:55 +08:00
[self.dashLineView mas_makeConstraints:^(MASConstraintMaker *make) {
2024-04-11 17:05:27 +08:00
make.leading.mas_equalTo(22);
make.trailing.mas_equalTo(-8);
2023-07-06 16:54:13 +08:00
make.height.mas_equalTo(1);
make.bottom.mas_equalTo(0);
}];
}
- (void)layoutSubviews {
[super layoutSubviews];
2023-07-14 18:50:55 +08:00
if (self.shapeLayer.superlayer == nil && self.dashLineView.frame.size.width > 0) {
[self addDashLineLength:5 lineSpacing:5 lineColor:[UIColorFromRGB(0x939BA3) colorWithAlphaComponent:0.3]];
2023-07-06 16:54:13 +08:00
}
}
2023-07-14 18:50:55 +08:00
- (void)addDashLineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor {
[self.shapeLayer setBounds:self.dashLineView.bounds];
[self.shapeLayer setPosition:CGPointMake(CGRectGetWidth(self.dashLineView.frame) / 2, CGRectGetHeight(self.dashLineView.frame))];
2023-07-06 16:54:13 +08:00
[self.shapeLayer setFillColor:[UIColor clearColor].CGColor];
[self.shapeLayer setStrokeColor:lineColor.CGColor];
2023-07-14 18:50:55 +08:00
[self.shapeLayer setLineWidth:CGRectGetHeight(self.dashLineView.frame)];
2023-07-06 16:54:13 +08:00
[self.shapeLayer setLineJoin:kCALineJoinRound];
[self.shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];
2023-07-14 18:50:55 +08:00
//
2023-07-06 16:54:13 +08:00
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0, 0);
2023-07-14 18:50:55 +08:00
CGPathAddLineToPoint(path, NULL,CGRectGetWidth(self.dashLineView.frame), 0);
2023-07-06 16:54:13 +08:00
[self.shapeLayer setPath:path];
CGPathRelease(path);
2023-07-14 18:50:55 +08:00
// 线
[self.dashLineView.layer addSublayer:self.shapeLayer];
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
- (void)setCornerTop:(BOOL)isTop bottom:(BOOL)isBottom {
if (isTop == NO && isBottom == NO) {
2023-07-06 16:54:13 +08:00
self.containerView.layer.cornerRadius = 0;
2023-07-14 18:50:55 +08:00
self.dashLineView.hidden = NO;
2023-07-06 16:54:13 +08:00
return;
}
2023-07-14 18:50:55 +08:00
if (isTop) {
2023-07-06 16:54:13 +08:00
self.containerView.layer.cornerRadius = 20.0;
self.containerView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
2023-07-14 18:50:55 +08:00
self.dashLineView.hidden = NO;
2023-07-06 16:54:13 +08:00
return;
}
2023-07-14 18:50:55 +08:00
if (isBottom) {
2023-07-06 16:54:13 +08:00
self.containerView.layer.cornerRadius = 20.0;
self.containerView.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
2023-07-14 18:50:55 +08:00
self.dashLineView.hidden = YES;
2023-07-06 16:54:13 +08:00
return;
}
}
2023-07-14 18:50:55 +08:00
- (void)setItemModel:(XPMineItemModel *)itemModel {
_itemModel = itemModel;
self.iconImageView.image = [UIImage imageNamed:itemModel.itemImageName];
self.titleLabel.text = itemModel.itemName;
2023-07-06 16:54:13 +08:00
}
#pragma mark -
- (UIView *)containerView {
if (!_containerView) {
_containerView = [[UIView alloc] init];
_containerView.backgroundColor = UIColor.whiteColor;
}
return _containerView;
}
2023-07-14 18:50:55 +08:00
- (NetImageView *)iconImageView {
if (!_iconImageView) {
_iconImageView = [[NetImageView alloc] init];
_iconImageView.contentMode = UIViewContentModeScaleAspectFit;
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
return _iconImageView;
2023-07-06 16:54:13 +08:00
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
2023-07-14 18:50:55 +08:00
_titleLabel.textColor = [DJDKMIMOMColor secondTextColor];
2023-07-06 16:54:13 +08:00
_titleLabel.font = [UIFont systemFontOfSize:12];
}
return _titleLabel;
}
2023-07-14 18:50:55 +08:00
- (UIImageView *)arrowImageView {
if (!_arrowImageView) {
_arrowImageView = [[UIImageView alloc] init];
2024-04-12 15:55:09 +08:00
_arrowImageView.image = [[UIImage imageNamed:@"common_right_arrow"]ms_SetImageForRTL];
2023-07-14 18:50:55 +08:00
_arrowImageView.contentMode = UIViewContentModeScaleAspectFit;
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
return _arrowImageView;
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
- (UIView *)dashLineView {
if (!_dashLineView) {
_dashLineView = [[UIView alloc] init];
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
return _dashLineView;
2023-07-06 16:54:13 +08:00
}
- (CAShapeLayer *)shapeLayer {
if (!_shapeLayer) {
_shapeLayer = [CAShapeLayer layer];
}
return _shapeLayer;
}
@end