0
我使用不同的按钮来改变使用CGContext的UIBezierPath曲线图的笔触颜色,但改变颜色先前绘制的线也根据最后的笔触颜色改变颜色。但我不想早期绘制的线条改变颜色。 任何帮助表示赞赏。 我用下面的代码:添加CGContextSaveGState(bluecontext);
和CGContextRestoreGState(bluecontext);
CGContext:改变整个视图的颜色,如果我改变笔触颜色
(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];
}
}