How to draw an UIImage or directly in -drawRect:?
问题 I have an UIImage which I want to draw on a UIView . But instead of creating an UIImageView and adding this as a subview, I want to overwrite -drawRect: and draw my UIView directly. For example, my code looks like: - (void)drawRect:(CGRect)rect { CGContextRef myContext = UIGraphicsGetCurrentContext(); UIImage *img = [UIImage imageNamed:@"foo.png"]; // how to draw the directly into the view now? } 回答1: Call [img drawInRect:rect]; . 回答2: BTW, you shouldn't load the image file in the drawRect