Bogdan
Bogdan

Reputation: 2617

iPhone - extend UIImage for custom drawing at runtime

How can I subclass and draw on an UIImage directly?

I tried extending it and draw on drawAtPoint: or drawInRect: using CoreGraphics, but the image is blank. And neither of the above 2 draw methods are called.

Please don't answer me that I can draw on the UIView because I need a custom runtime designed UIImage.

Upvotes: 2

Views: 1039

Answers (1)

tia
tia

Reputation: 9698

It's clearly stated in the UIImageView document:

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIImageView_Class/Reference/Reference.html

Subclassing Notes Special Considerations

The UIImageView class is optimized to draw its images to the display. UIImageView will not call drawRect: a subclass. If your subclass needs custom drawing code, it is recommended you use UIView as the base class.

Because telling you to use UIView instead is now allowed, I'll just answer that it's impossible to override drawRect: for UIImageView.

Upvotes: 2

Related Questions