I have the following code that I a开发者_C百科m using to draw a simple rectangle inside the middle of a drawn circle, however I would like to be able to replace this rectangle with an UIImage, does anyone know how this can be done?
CGContextSetRGBStrokeColor(context, 255.0/255.0, 255.0/255.0, 255.0/255.0, 1.0);
CGMutablePathRef path = [self newPathForRect:CGRectMake(center.x - kRoundedRectRadius, center.y - kRoundedRectRadius, kRoundedRectRadius * 2.0, kRoundedRectRadius * 2.0)];
CGContextAddPath(context, path);
CGContextDrawPath(context, kCGPathStroke);
CGPathRelease(path);
You'll no longer be able to use a CGPathRef
to do it, but the CGContextDrawImage() function will do what you want. Just pass in the result of -[UIImage CGImage]
:
rect = CGRectMake(
center.x - kRoundedRectRadius,
center.y - kRoundedRectRadius,
kRoundedRectRadius * 2.0,
kRoundedRectRadius * 2.0
);
CGContextDrawImage(context, rect, myImage.CGImage);
精彩评论