iPhone - a question about drawRect
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:
- will the stuff being drawn on the image itself or in a kind of "layer" totally independent?
- if the later is true, how do I access this "layer"?
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.
精彩评论