I am developing a paint app for my first try in iOS development.
I am trying to make a color palette that will change my brush’s color on button click but i don’t know how. I already have UIButtons that are connected to its reference outlets and sent event but my codes are not working.
here:
- (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;
}
Stop resetting your color to black at the top of the method. Remove these lines: