I have a custom view inheriting from UIView.
In this view, there is an image which is always the same and I only want to draw on top of that.
However, in order for the image to be drawn, I have to call drawInRect every time the draw cycle runs.
- (void)drawRect:(CGRect)rect{
CGContextRef context = UIGraphicsGetCurrentContext();
[image drawInRect:self.bounds];
// drawing....
}
Is there a way to show the image and not to call this method every time drawRect is invoked?
Thank you.
Put the image in a
UIImageViewunderneath your customUIViewinstead of drawing it indrawRect:. Make your custom view’s background colorclearColorso the image shows through wheredrawRect:doesn’t draw anything.Don’t try to make the image view a subview of your custom view. A subview always draws on top of its superview’s content. You could make your custom view a subview of the image view, or you could make them siblings.