I draw an initial simple rect using UIBezierPath and fill it with color. How can I change only its color by touching on it?
- (void) drawRect:(CGRect)rect
{
// Drawing code
[self drawRectWithFrame:_myRect fillColor:_firstColor];
}
- (void) drawRectWithFrame:(CGRect)frame fillColor:(UIColor *)color
{
[color setFill];
UIBezierPath *path = [UIBezierPath bezierPathWithRect:frame];
[path fill];
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//get the rect color from touches (pixel color)
UIColor *color = [self getRectColorFromTouches:touches];
//chnage the rect color
if (color == _firstColor) {
//doesn't work
//[self drawRectWithFrame:_myRect fillColor:_secondColor]; //??
//How can I do that?
}
else {
//??
}
}