196 lines
6.2 KiB
Objective-C
196 lines
6.2 KiB
Objective-C
//
|
|
// YMMineItemTableViewCell.m
|
|
// YUMI
|
|
//
|
|
// Created by XY on 2023/2/20.
|
|
//
|
|
|
|
#import "XPMineItemTableViewCell.h"
|
|
#import "NetImageView.h"
|
|
#import <Masonry.h>
|
|
#import "DJDKMIMOMColor.h"
|
|
#import "UIView+Corner.h"
|
|
#import "YUMIMacroUitls.h"
|
|
|
|
#import "XPMineItemModel.h"
|
|
|
|
@interface XPMineItemTableViewCell()
|
|
|
|
/// 容器
|
|
@property (nonatomic, strong) UIView *containerView;
|
|
/// 图标
|
|
@property (nonatomic, strong) NetImageView *iconImageView;
|
|
/// 标题
|
|
@property (nonatomic, strong) UILabel *titleLabel;
|
|
/// 箭头
|
|
@property (nonatomic, strong) UIImageView *arrowImageView;
|
|
/// 虚线
|
|
@property (nonatomic, strong) UIView *dashLineView;
|
|
@property (nonatomic, strong) CAShapeLayer *shapeLayer;
|
|
|
|
@end
|
|
|
|
@implementation XPMineItemTableViewCell
|
|
|
|
- (void)awakeFromNib {
|
|
[super awakeFromNib];
|
|
// Initialization code
|
|
}
|
|
|
|
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
|
|
[super setSelected:selected animated:animated];
|
|
|
|
// Configure the view for the selected state
|
|
}
|
|
|
|
- (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;
|
|
[self createUI];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)createUI {
|
|
[self.contentView addSubview:self.containerView];
|
|
[self.containerView addSubview:self.iconImageView];
|
|
[self.containerView addSubview:self.titleLabel];
|
|
[self.containerView addSubview:self.arrowImageView];
|
|
[self.containerView addSubview:self.dashLineView];
|
|
|
|
[self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(16);
|
|
make.trailing.mas_equalTo(-16);
|
|
make.top.bottom.mas_equalTo(0);
|
|
}];
|
|
[self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(12);
|
|
make.centerY.mas_equalTo(self.containerView);
|
|
make.width.height.mas_equalTo(40);
|
|
}];
|
|
[self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.trailing.mas_equalTo(0);
|
|
make.width.mas_equalTo(40);
|
|
make.height.mas_equalTo(12);
|
|
make.centerY.mas_equalTo(self.containerView);
|
|
}];
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(self.iconImageView.mas_trailing).offset(2);
|
|
make.trailing.mas_equalTo(self.arrowImageView.mas_leading).offset(-2);
|
|
make.centerY.mas_equalTo(self.containerView);
|
|
}];
|
|
[self.dashLineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(22);
|
|
make.trailing.mas_equalTo(-8);
|
|
make.height.mas_equalTo(1);
|
|
make.bottom.mas_equalTo(0);
|
|
}];
|
|
|
|
}
|
|
|
|
- (void)layoutSubviews {
|
|
[super layoutSubviews];
|
|
if (self.shapeLayer.superlayer == nil && self.dashLineView.frame.size.width > 0) {
|
|
[self addDashLineLength:5 lineSpacing:5 lineColor:[UIColorFromRGB(0x939BA3) colorWithAlphaComponent:0.3]];
|
|
}
|
|
}
|
|
|
|
- (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))];
|
|
[self.shapeLayer setFillColor:[UIColor clearColor].CGColor];
|
|
[self.shapeLayer setStrokeColor:lineColor.CGColor];
|
|
[self.shapeLayer setLineWidth:CGRectGetHeight(self.dashLineView.frame)];
|
|
[self.shapeLayer setLineJoin:kCALineJoinRound];
|
|
[self.shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];
|
|
// 设置路径
|
|
CGMutablePathRef path = CGPathCreateMutable();
|
|
CGPathMoveToPoint(path, NULL, 0, 0);
|
|
CGPathAddLineToPoint(path, NULL,CGRectGetWidth(self.dashLineView.frame), 0);
|
|
[self.shapeLayer setPath:path];
|
|
CGPathRelease(path);
|
|
// 把绘制好的虚线添加上来
|
|
[self.dashLineView.layer addSublayer:self.shapeLayer];
|
|
}
|
|
|
|
- (void)setCornerTop:(BOOL)isTop bottom:(BOOL)isBottom {
|
|
if (isTop == NO && isBottom == NO) {
|
|
self.containerView.layer.cornerRadius = 0;
|
|
self.dashLineView.hidden = NO;
|
|
return;
|
|
}
|
|
if (isTop) {
|
|
self.containerView.layer.cornerRadius = 20.0;
|
|
self.containerView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
|
|
self.dashLineView.hidden = NO;
|
|
return;
|
|
}
|
|
if (isBottom) {
|
|
self.containerView.layer.cornerRadius = 20.0;
|
|
self.containerView.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
|
|
self.dashLineView.hidden = YES;
|
|
return;
|
|
}
|
|
}
|
|
|
|
- (void)setItemModel:(XPMineItemModel *)itemModel {
|
|
_itemModel = itemModel;
|
|
self.iconImageView.image = [UIImage imageNamed:itemModel.itemImageName];
|
|
self.titleLabel.text = itemModel.itemName;
|
|
}
|
|
|
|
#pragma mark - 懒加载
|
|
|
|
- (UIView *)containerView {
|
|
if (!_containerView) {
|
|
_containerView = [[UIView alloc] init];
|
|
_containerView.backgroundColor = UIColor.whiteColor;
|
|
}
|
|
return _containerView;
|
|
}
|
|
|
|
- (NetImageView *)iconImageView {
|
|
if (!_iconImageView) {
|
|
_iconImageView = [[NetImageView alloc] init];
|
|
_iconImageView.contentMode = UIViewContentModeScaleAspectFit;
|
|
}
|
|
return _iconImageView;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.textColor = [DJDKMIMOMColor secondTextColor];
|
|
_titleLabel.font = [UIFont systemFontOfSize:12];
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (UIImageView *)arrowImageView {
|
|
if (!_arrowImageView) {
|
|
_arrowImageView = [[UIImageView alloc] init];
|
|
_arrowImageView.image = [[UIImage imageNamed:@"common_right_arrow"]ms_SetImageForRTL];
|
|
_arrowImageView.contentMode = UIViewContentModeScaleAspectFit;
|
|
}
|
|
return _arrowImageView;
|
|
}
|
|
|
|
- (UIView *)dashLineView {
|
|
if (!_dashLineView) {
|
|
_dashLineView = [[UIView alloc] init];
|
|
}
|
|
return _dashLineView;
|
|
}
|
|
|
|
- (CAShapeLayer *)shapeLayer {
|
|
if (!_shapeLayer) {
|
|
_shapeLayer = [CAShapeLayer layer];
|
|
}
|
|
return _shapeLayer;
|
|
}
|
|
|
|
@end
|