我正在使用不同的按钮来更改使用 CGContext 绘制 UIBezierPath 曲线的笔触颜色,但是在更改颜色时,之前绘制的线条也会根据最后的笔触颜色改变颜色。但我不希望之前绘制的线条改变颜色。任何帮助表示赞赏。我使用了以下代码:
(void)drawRect:(CGRect)rect{
if(colorwith==1){
CGContextRef bluecontext = UIGraphicsGetCurrentContext();
CGContextBeginPath(bluecontext); // clears any previous path
CGContextSetRGBFillColor(bluecontext, 0.2, 0.3, 0.5, .06);
CGContextSetStrokeColorWithColor(bluecontext, [UIColor blueColor].CGColor);
CGContextStrokePath(bluecontext); // draw blue line
for(UIBezierPath *_tempPath in _arrayForOperationPath)
{
[_tempPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
}
//[[UIColor blackColor]setStroke];
}
else if (colorwith==2){
CGContextRef bluecontextt = UIGraphicsGetCurrentContext();
CGContextBeginPath(bluecontextt); // clears any previous path
CGContextSetRGBFillColor(bluecontextt, 0.2, 0.8, 0.7, .01);
CGContextSetStrokeColorWithColor(bluecontextt, [UIColor redColor].CGColor);
CGContextStrokePath(bluecontextt);
// [[UIColor redColor]setStroke];
for(UIBezierPath *_tempPath in _arrayForOperationPath)
{
[_tempPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
}
//[[UIColor blackColor]setStroke];
}
}