我有一个 UIImage
,我想要在一个 UIView
上绘制它。但是,我不想创建一个 UIImageView
并将其添加为子视图,而是想覆盖 -drawRect:
方法并直接绘制我的 UIView。
例如,我的代码如下:
- (void)drawRect:(CGRect)rect {
CGContextRef myContext = UIGraphicsGetCurrentContext();
UIImage *img = [UIImage imageNamed:@"foo.png"];
// how to draw the directly into the view now?
}
[img drawAtPoint:point]
,但我更喜欢使用drawInRect:
。 - Sam Soffes