我希望有一个标记物,用红色标注,但不确定是否可以实现。
看起来像是用毛笔笔尖标注。
试着按照“Andrey”的回答尝试以下代码后,我得到了以下带空格的绘图输出。
刷子图片可以在这里找到,使用的是
对代码进行进一步更改后,我发现仍然无法获得预期的结果。
在这里,我正在尝试填充当前点和下一个点之间存在的路径。
看起来像是用毛笔笔尖标注。
试着按照“Andrey”的回答尝试以下代码后,我得到了以下带空格的绘图输出。
刷子图片可以在这里找到,使用的是
![enter image description here](https://istack.dev59.com/IewSX.webp)
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGFloat w=5.0;
CGFloat h=2.0;
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
for(int i=0;i<self.positions.count;i++){
CGPoint point=[[self.positions objectAtIndex:i] CGPointValue];
CGFloat x=point.x-(w/2.0);
CGFloat y=point.y-(h/2.0);
CGContextFillRect(context, CGRectMake(x, y, w, h));
if(i+1<self.positions.count){
CGPoint nextPoint=[[self.positions objectAtIndex:(i+1)] CGPointValue];
CGMutablePathRef myPath=CGPathCreateMutable();
CGPathMoveToPoint(myPath, NULL, x, y);
CGFloat x1=nextPoint.x-(w/2.0);
CGFloat y1=nextPoint.y-(h/2.0);
CGPathAddLineToPoint(myPath, NULL, x1, y1);
CGPathAddLineToPoint(myPath, NULL, w, y1);
CGPathAddLineToPoint(myPath, NULL, w, y);
CGPathCloseSubpath(myPath);
CGContextFillPath(context);
}
}
}