Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

iphone - 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?
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Call [img drawInRect:rect];.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...