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.
132 lines
4.0 KiB
132 lines
4.0 KiB
// |
|
// NweTrackMsgCell.m |
|
// tongxin |
|
// |
|
// Created by weichao on 2019/8/23. |
|
// Copyright © 2019 xTT. All rights reserved. |
|
// |
|
|
|
#import "NewTrackMsgCell.h" |
|
|
|
@interface NewTrackMsgCell() |
|
{ |
|
CAShapeLayer *shapeLayer; |
|
} |
|
@end |
|
@implementation NewTrackMsgCell |
|
|
|
- (void)awakeFromNib { |
|
[super awakeFromNib]; |
|
// Initialization code |
|
self.selectionStyle = UITableViewCellSelectionStyleNone; |
|
|
|
self.iconView.contentMode = UIViewContentModeCenter; |
|
self.addressLabel.text = @""; |
|
self.addressLabel.numberOfLines = 0; |
|
self.addressLabel.font = [UIFont systemFontOfSize:12]; |
|
|
|
|
|
self.dottedLineView.backgroundColor = [UIColor whiteColor]; |
|
|
|
|
|
|
|
// icon_track_fixed_point |
|
} |
|
/** |
|
设置类型和时间和地址 |
|
|
|
@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_track_start_point"]; |
|
|
|
break; |
|
case 1: |
|
self.iconView.image = [UIImage imageNamed:@"icon_track_fixed_point"]; |
|
|
|
break; |
|
case 2: |
|
self.iconView.image = [UIImage imageNamed:@"icon_track_end_point"]; |
|
|
|
break; |
|
default: |
|
self.iconView.image = [UIImage imageNamed:@"icon_track_fixed_point"]; |
|
break; |
|
} |
|
if (canShape) { |
|
//绘制虚线 |
|
[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; |
|
self.stayLabelWidth.constant = [self getWidthWithString:stayTime font:[UIFont systemFontOfSize:12]] + 8; |
|
} |
|
} |
|
|
|
- (CGFloat)getWidthWithString:(NSString *)string font:(UIFont *)font{ |
|
NSDictionary *attrs = @{NSFontAttributeName:font}; |
|
CGFloat width = [string boundingRectWithSize:CGSizeZero options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size.width; |
|
return width; |
|
} |
|
|
|
- (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, 10); |
|
}else{ |
|
CGPathMoveToPoint(path, NULL, 0, 0); |
|
} |
|
|
|
//设置虚线绘制路径终点 |
|
CGPathAddLineToPoint(path, NULL, 0, view.height); |
|
//设置虚线绘制路径 |
|
[shapeLayer setPath:path]; |
|
CGPathRelease(path); |
|
//添加虚线 |
|
[view.layer addSublayer:shapeLayer]; |
|
} |
|
|
|
- (void)setSelected:(BOOL)selected animated:(BOOL)animated { |
|
[super setSelected:selected animated:animated]; |
|
|
|
// Configure the view for the selected state |
|
} |
|
|
|
@end
|
|
|