You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
219 lines
7.0 KiB
219 lines
7.0 KiB
![]()
2 years ago
|
//
|
||
|
// TrackTableViewCell.m
|
||
|
// LekangGuard
|
||
|
//
|
||
|
// Created by ecell on 2022/12/14.
|
||
|
//
|
||
|
|
||
|
#import "TrackTableViewCell.h"
|
||
|
|
||
|
@interface TrackTableViewCell ()
|
||
|
{
|
||
|
CAShapeLayer *shapeLayer;
|
||
|
}
|
||
|
|
||
|
/// 时间
|
||
|
@property (weak, nonatomic) UILabel *timeLabel;
|
||
|
|
||
|
/// 虚线View
|
||
|
@property (weak, nonatomic) UIView *dottedLineView;
|
||
|
|
||
|
/// 图标
|
||
|
@property (weak, nonatomic) UIImageView *iconView;
|
||
|
|
||
|
/// 地址
|
||
|
@property (weak, nonatomic) UILabel *addressLabel;
|
||
|
|
||
|
/// 停留时间
|
||
|
@property (weak, nonatomic) UILabel *stayLabel;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation TrackTableViewCell
|
||
|
|
||
|
|
||
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
|
||
|
{
|
||
|
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
||
|
if (self)
|
||
|
{
|
||
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
||
|
self.backgroundColor = KKWhiteColorColor;
|
||
|
[self subCellView];
|
||
|
}
|
||
|
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
- (void)subCellView
|
||
|
{
|
||
|
UILabel *timeLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(12) textColor:KKTextBlackColor text:@"" Radius:0];
|
||
|
self.timeLabel = timeLabel;
|
||
|
[self.contentView addSubview:timeLabel];
|
||
|
[timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(self.contentView).offset(20);
|
||
|
make.top.equalTo(self.contentView.mas_top).offset(10);
|
||
|
}];
|
||
|
|
||
|
|
||
|
UIView *dottedLineView = [UIView new];
|
||
|
self.dottedLineView = dottedLineView;
|
||
|
[self.contentView addSubview:dottedLineView];
|
||
|
[dottedLineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(self.contentView).offset(65);
|
||
|
make.top.equalTo(self.contentView.mas_top);
|
||
|
make.bottom.equalTo(self.contentView.mas_bottom);
|
||
|
make.width.mas_equalTo(1);
|
||
|
}];
|
||
|
|
||
|
UIImageView *iconView = [UIImageView new];
|
||
|
self.iconView = iconView;
|
||
|
[self.contentView addSubview:iconView];
|
||
|
[iconView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerX.equalTo(dottedLineView);
|
||
|
make.centerY.equalTo(timeLabel.mas_centerY);
|
||
|
make.size.mas_equalTo(CGSizeMake(20, 25));
|
||
|
}];
|
||
|
|
||
|
UILabel *addressLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:Font_(15) textColor:KKTextBlackColor text:@"" Radius:0];
|
||
|
self.addressLabel = addressLabel;
|
||
|
[self.contentView addSubview:addressLabel];
|
||
|
[addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(iconView.mas_right).offset(15);
|
||
|
make.right.equalTo(self.contentView.mas_right).inset(15);
|
||
|
make.top.equalTo(iconView.mas_top).offset(2);
|
||
|
}];
|
||
|
|
||
|
UILabel *stayLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(12) textColor:KKGrey121 text:@"" Radius:0];
|
||
|
self.stayLabel = stayLabel;
|
||
|
[self.contentView addSubview:stayLabel];
|
||
|
[stayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(addressLabel.mas_left);
|
||
|
make.top.equalTo(addressLabel.mas_bottom).offset(10);
|
||
|
make.height.mas_equalTo(Adapted(18));
|
||
|
make.bottom.equalTo(self.contentView.mas_bottom).inset(8);
|
||
|
}];
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
设置类型和时间和地址
|
||
|
|
||
|
@param type 0 起点 1 平常点 2 终点
|
||
|
@param address 地址
|
||
|
@param timeStr 时间
|
||
|
@param canShape 是否绘制虚线
|
||
|
*/
|
||
|
- (void)setIconType:(NSInteger)type WithAddress:(NSString *)address WithTime:(NSString*)timeStr CanShapeToView:(BOOL)canShape StayTime:(NSString *)stayTime
|
||
|
{
|
||
|
switch (type) {
|
||
|
case 0:
|
||
|
self.iconView.image = [UIImage imageNamed:@"icon_start_point"];
|
||
|
|
||
|
break;
|
||
|
case 1:
|
||
|
self.iconView.image = [UIImage imageNamed:@"icon_fixed_point"];
|
||
|
|
||
|
break;
|
||
|
case 2:
|
||
|
self.iconView.image = [UIImage imageNamed:@"icon_end_point_1"];
|
||
|
|
||
|
break;
|
||
|
default:
|
||
|
self.iconView.image = [UIImage imageNamed:@"icon_fixed_point"];
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
[self.iconView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerX.equalTo(self.dottedLineView);
|
||
|
make.centerY.equalTo(self.timeLabel.mas_centerY);
|
||
|
make.size.mas_equalTo(self.iconView.image.size);
|
||
|
}];
|
||
|
|
||
|
CGRect rect = [UICommon GetTextWidth:stayTime ViewHeight:Adapted(18) fontSize:Font_(12) type:@"w"];
|
||
|
[self.stayLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(self.addressLabel.mas_left);
|
||
|
make.top.equalTo(self.addressLabel.mas_bottom).offset(10);
|
||
|
make.width.mas_equalTo(Adapted(rect.size.width)+8);
|
||
|
make.height.mas_equalTo(Adapted(18));
|
||
|
make.bottom.equalTo(self.contentView.mas_bottom).inset(8);
|
||
|
}];
|
||
|
|
||
|
|
||
|
if (canShape) {
|
||
|
//绘制虚线
|
||
|
NSLog(@"ffffffff-------->%f",self.stayLabel.bottom+8);
|
||
|
self.dottedLineView.frame = CGRectMake(65, 0, 1, self.stayLabel.bottom+8);
|
||
|
[self shapeToView:self.dottedLineView WithType:type];
|
||
|
}else{
|
||
|
//清除虚线
|
||
|
[shapeLayer removeFromSuperlayer];
|
||
|
shapeLayer = nil;
|
||
|
}
|
||
|
self.addressLabel.text = address;
|
||
|
self.timeLabel.text = timeStr;
|
||
|
|
||
|
if ([@"0" isEqualToString:stayTime]) {
|
||
|
self.stayLabel.hidden = YES;
|
||
|
} else {
|
||
|
self.stayLabel.hidden = NO;
|
||
|
self.stayLabel.layer.masksToBounds = true;
|
||
|
self.stayLabel.layer.cornerRadius = 6;
|
||
|
self.stayLabel.text = stayTime;
|
||
|
self.stayLabel.textColor = [UIColor whiteColor];
|
||
|
self.stayLabel.backgroundColor = RGB(0xCC, 0xCC, 0xCC);
|
||
|
self.stayLabel.textAlignment = NSTextAlignmentCenter;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
- (void)shapeToView:(UIView *)view WithType:(NSInteger)type
|
||
|
{
|
||
|
if(shapeLayer){
|
||
|
return;
|
||
|
}
|
||
|
shapeLayer = [CAShapeLayer layer];
|
||
|
[shapeLayer setBounds:view.bounds];
|
||
|
//设置锚点
|
||
|
[shapeLayer setPosition:CGPointMake(view.frame.size.width / 2.0, view.frame.size.height/2.0)];
|
||
|
[shapeLayer setFillColor:[UIColor clearColor].CGColor];
|
||
|
//设置虚线颜色
|
||
|
[shapeLayer setStrokeColor:[UIColor lightGrayColor].CGColor];
|
||
|
//设置虚线宽度
|
||
|
[shapeLayer setLineWidth:1];
|
||
|
[shapeLayer setLineJoin:kCALineJoinRound];
|
||
|
//设置虚线的线宽及间距
|
||
|
[shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:2],[NSNumber numberWithInt:2], nil]];
|
||
|
//创建虚线绘制路径
|
||
|
CGMutablePathRef path = CGPathCreateMutable();
|
||
|
//设置虚线绘制路径起点
|
||
|
if(type == 2){ //终点
|
||
|
CGPathMoveToPoint(path, NULL, 0, 100);
|
||
|
}else{
|
||
|
CGPathMoveToPoint(path, NULL, 0, 0);
|
||
|
}
|
||
|
|
||
|
//设置虚线绘制路径终点
|
||
|
CGPathAddLineToPoint(path, NULL, 0, view.height);
|
||
|
//设置虚线绘制路径
|
||
|
[shapeLayer setPath:path];
|
||
|
CGPathRelease(path);
|
||
|
//添加虚线
|
||
|
[view.layer addSublayer:shapeLayer];
|
||
|
}
|
||
|
|
||
|
- (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
|
||
|
}
|
||
|
|
||
|
@end
|