iPhone - 扩展 UIImage 以在运行时自定义绘图

标签 iphone objective-c uiimage subclass

如何子类化并直接在 UIImage 上绘图?

我尝试扩展它并使用 CoreGraphicsdrawAtPoint:drawInRect: 上绘制,但是 image 是空白的。并且上面2个draw方法都没有被调用。

请不要回答我可以在 UIView 上绘图,因为我需要一个自定义运行时设计的 UIImage

最佳答案

UIImageView文档中明确指出:

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.

因为现在允许您使用 UIView 来代替,所以我只会回答,不可能覆盖 UIImageViewdrawRect:

关于iPhone - 扩展 UIImage 以在运行时自定义绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11361690/

相关文章:

iphone - XCode 4.5 Storyboard 不显示我的 View Controller 的一些导航栏

iphone - 如何触发属性更改的方法?

ios - 当我将许多大图像合并到一个 UIImage 中时,UIImage 为空白

iphone - 如何裁剪固定尺寸的 UIImage?

iphone - CGAffineTransform重置

iphone - ViewController长度无法识别的选择器已发送到iPhone中的实例

javascript - 当 native 键盘在移动设备上可见时禁用滚动

objective-c - UIScrollView 不会在设备上滚动

objective-c - IBOutlet 为零的原因

swift - while 循环缩小图像大小,无论运行多少次迭代都无法低于 400kB