如何子类化并直接在 UIImage
上绘图?
我尝试扩展它并使用 CoreGraphics
在 drawAtPoint:
或 drawInRect:
上绘制,但是 image
是空白的。并且上面2个draw方法都没有被调用。
请不要回答我可以在 UIView
上绘图,因为我需要一个自定义运行时设计的 UIImage
。
最佳答案
UIImageView
文档中明确指出:
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.
因为现在允许您使用 UIView
来代替,所以我只会回答,不可能覆盖 UIImageView
的 drawRect:
。
关于iPhone - 扩展 UIImage 以在运行时自定义绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11361690/