0
您好想在我嘗試着色的項目中選擇顏色。 我是新來的,所以這可能是一個愚蠢的問題。我正在使用按鈕來選擇不同的顏色。但是,當按下按鈕時,唯一發生的事情是繪製線條的最後一個像素變爲所選顏色。在第一個標籤下面的代碼刪除圖紙和第二應該改變顏色爲將要繪製的下一行...更改顏色
-(IBAction)buttonClicked:(UIButton *)sender {
switch (sender.tag)
{
case 1: {
drawImage.image = nil;
return;
}
//lastPoint.y -= 0;
break;
case 2: {
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 3.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 1.0, 2.0, 1.0);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
break;
default:
break;
}
}