【发布时间】:2018-07-11 07:18:08
【问题描述】:
我在向 UIBezierPath 添加箭头时需要帮助。 我使用 UIBezierPath 创建了多行,它们在不同的方向。 现在,我想在线的终点创建箭头。
我尝试使用 NSAttributedString 将 UIImage 添加到 UILable 到使用 NSTextAttachment 的 UILable。
但是,这里的问题是箭头总是向下。我想沿着这条线对齐箭头。
这是我的代码:
UIBezierPath *ShotPath = [UIBezierPath bezierPath];
NSValue *PointValue = [[[PathArray objectAtIndex:i] valueForKey:@"ShotPath"] objectAtIndex:k];
CGPoint FirstPoint; = [PointValue CGPointValue];
[ShotPath moveToPoint:FirstPoint];
CAShapeLayer *line = [CAShapeLayer layer];
line.lineWidth = 4.0;
line.path=ShotPath.CGPath;
line.fillColor = [UIColor clearColor].CGColor;
line.strokeColor = [UIColor colorWithRed:231/255.0 green:83/255.0 blue:73/255.0 alpha:1].CGColor;
[[BaseView layer] addSublayer:line];
NSValue *PointValue = [[[PathArray objectAtIndex:i] valueForKey:@"ShotPath"] objectAtIndex:[[[PathArray objectAtIndex:i] valueForKey:@"ShotPath"] count]-1];
CGPoint OtherPoint = [PointValue CGPointValue];
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(OtherPoint.x-6, OtherPoint.y-8, 12, 12)];
lbl.backgroundColor =[UIColor clearColor];
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [UIImage imageNamed:@"DropDown_Icon"];
NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
lbl.attributedText = attachmentString;
[lbl setTextColor:[UIColor blackColor]];
lbl.font =[UIFont boldSystemFontOfSize:22.0];
[BaseView addSubview:lbl];
这是我当前的输出:
【问题讨论】:
-
显示你当前的代码和结果
-
你好@Tj3n 请检查我编辑的问题
标签: ios objective-c uibezierpath quartz-core