Posted by: bearc0025 | May 6, 2011

Drawing to the screen. – iFans – iPad, iPhone, and iPod touch Fans forums

This is a useful tutorial on how to draw to a UIImageView.

via [Tutorial] Drawing to the screen. – iFans – iPad, iPhone, and iPod touch Fans forums.

I made some changes to the code (not to say you need to): I…

  • subclass UIImageView
  • change drawImage.image to self.image
  • added to init: self.userInteractionEnabled = YES;
  • made the double-tap-to-clear a setting and added a similar setting for double-tap-to-erase
  • double-tap-to-erase uses CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear); – works like an eraser (otherwise use CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeColor);)
  • added UIColor and float setter for draw color and alpha (alpha sets self.alpha – works better than setting the stroke alpha)
  • use [strokeColor setStroke]; to set the stroke color
  • extracted out the context drawing into a method and call it w/ whatever the end point is (either currentPoint or lastPoint)

The result is a UIImageView subclass that takes a color and alpha and optionally either clears all or toggles erase mode w/ a double tap.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: