我已经查看了各种类似的问题,但似乎仍然无法让我的代码正常工作。我有一个带有图像的 UIView ( [image drawInRect:bounds]
),但我在上下文剪辑中遗漏了一些东西:
// Get context & bounds, and calculate centre & radius
CGContextRef ctx=UIGraphicsGetCurrentContext();
CGRect bounds=[self bounds];
CGPoint centre;
centre.x=bounds.origin.x+0.5*bounds.size.width;
centre.y=bounds.origin.y+0.5*bounds.size.height;
CGFloat radius=centre.x;
// Draw image
UIImage *backImage=[UIImage imageNamed:@"backimage.png"];
[backImage drawInRect:bounds];
// Create clipping path and clip context
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddArc(path, NULL, centre.x, centre.y, radius, 0, 2*M_PI, 0);
CGContextAddPath(ctx, path);
CGContextClip(ctx);
关于我哪里出错的任何想法?谢谢阅读。