Suppose that instead a UIView I subclass a UIImageView and assign a background image to it, like in
UIImageView *myImageView = [[UIImageView alloc] initWithImage: //... bla bla
and then I implement a drawRect method and use it to draw stuff on the image.
My question is:
thanks
If you override drawRect, the stuff will be drawn on the image itself. Every UIImage
is backed by a CALayer
, so you're really drawing everything onto that. Access it with
[image layer];
You should subclass UIView, not UIImageView if you need custom drawing.
From the UIImageView class reference
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.