What is the best way to go about making an app that does the following: the user taps at locations, and on the locations, a square is drawn. There is no way to erase the squares. You simply tap wherever you want and squares of a predefined size are drawn.
I was thinking to make a custom UIView and override the drawRect method by keeping a list of all the (x,y) locations of the squares and then calling [customView setNeedsDisplay] and drawing all the squares everytime a new square is drawn.
Is there a better way?
In Java, I would use an offscreen image, draw the square onto the offscreen image, and then draw the image onto the screen on every repaint() call. But, is this good to do for iPad? If so, what is code that will let me initialize a UIImage and draw a square onto it?
You could just add an empty
UIView, which you only set the background color on, and then add it to the view you are tapping.Example of adding a yellow square in the viewcontroller’s
viewDidLoadNote: You can also give each square an id in its
tagand later retrieve them withviewWithTag:from their superview (i.e.self.viewfrom the controller)