1

I have this UIImage in a UIImageView:

enter image description here

I want it so that when a user touches inside of any box, it fills with a blue color.

This is just an example... the actual image I am going to use is not squares, but a more complex line drawing, so drawing it with code would be extremely complex.

What is the best way to accomplish this?

Ethan Allen
  • 14,425
  • 24
  • 101
  • 194
  • 3
    why do you have an image like this. If filling up the rects with a color is your requirement. Use a custom UIView instead. and draw these rects using CGContext, and when user clicks on the view, call setNeedsDisplay on the view, which will call drawRect for the view. There you can fill those rects. – devluv May 24 '13 at 05:30
  • [How to draw a Rectangle in -drawRect:](http://stackoverflow.com/a/8195162/1059705) and `- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;` will help you .. – Bala May 24 '13 at 07:31
  • This is just an example folks... the actual image I am going to use is not squares, but a more complex line drawing. – Ethan Allen May 24 '13 at 17:10

2 Answers2

1

You can go with flood fill Algorithm.

That is the best way to fill any image.

there is some links for that

http://en.wikipedia.org/wiki/Flood_fill

and get sample code from here

Flood Fill

virantporwal
  • 989
  • 2
  • 6
  • 26
0

Use UIView and implement its drawrect method to show the colors.Use QuartzCore and CoreGraphics to draw. Implement the touch with drawing of color to the view.

Regexident
  • 29,441
  • 10
  • 93
  • 100
Lithu T.V
  • 19,955
  • 12
  • 56
  • 101