How do I use Core Graphics to draw inside of a instantiated UIImageView (No class files to override drawrect with — just a reference to the instance)? I want to draw a simple point of fixed width (say, 10 pixels diameter) and of a certain color.
Share
0and an end angle of2 * M_PI.I know that on the Mac, that’s really not a good idea, as an NSView may redraw at any time if anything has set it as needing display (or told it directly to display), and would then clobber anything you’d drawn over it. No idea about the iPhone, but I do notice that UIView doesn’t have methods like NSView’s
lockFocusandunlockFocus.There’s a more architectural reason not to do this: Drawing is the exclusive domain of views, and you’re proposing to break that exclusivity and sprinkle some drawing code in (I’m assuming) a controller. Scattering code for a purpose in an object that doesn’t have that purpose is a path to messy, unnavigable code.
Better to make a subview for each point and add those as subviews of the image view, or subclass UIImageView, give your instance of that subclass an array of the points to draw, and have the subclass’s
drawRect:call up tosuperbefore drawing its points.The above solution, then, goes in
drawRect:.