1
我正在爲iOS開發中的第一次嘗試開發繪畫應用程序。如何改變按鈕點擊畫筆的顏色?
我想做一個調色板,將改變我按鈕點擊刷的顏色,但我不知道如何。我已經有UIButtons連接到它的參考插座併發送了事件,但是我的代碼不工作。
這裏:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
touchSwiped = YES;
redAmt = 0;
blueAmt = 0;
greenAmt = 0;
UITouch *touch = [touches anyObject];
CGPoint currentTouch = [touch locationInView:self.view];
currentTouch.y -= 20;
UIGraphicsBeginImageContext(self.view.frame.size);
[touchDraw.image drawInRect:CGRectMake(0, 0, touchDraw.frame.size.width, touchDraw.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 35.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), redAmt, blueAmt, greenAmt, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), endingPoint.x, endingPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentTouch.x, currentTouch.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
touchDraw.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
endingPoint = currentTouch;
touchMoved++;
if (touchMoved == 10) {
touchMoved = 0;
}
}
-(IBAction)blackInk:(id)sender
{
redAmt = 0;
blueAmt = 0;
greenAmt = 0;
}
-(IBAction)blueInk:(id)sender
{
redAmt = 0;
blueAmt = 0;
greenAmt = 1;
}
-(IBAction)redInk:(id)sender
{
redAmt = 1;
blueAmt = 1;
greenAmt = 0;
}
-(IBAction)greenInk:(id)sender
{
redAmt = 0;
blueAmt = 1;
greenAmt = 0;
}
謝謝!有效!! – SeongHo