我有一个圆形的UIBezierpath:
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:100];
Run Code Online (Sandbox Code Playgroud)
但后来我想用UIImage填充圆圈(仅显示圆圈内的图像的一部分)
最诚挚的问候克里斯蒂安
感谢Daniel和Dave的出色答案:D给我带来了很多麻烦; D
解决方案:
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextAddPath(ctx, path.CGPath);
CGContextClip(ctx);
Run Code Online (Sandbox Code Playgroud)
和:
path.addClip;
Run Code Online (Sandbox Code Playgroud)
两者都很完美,但我最终使用了最后一种方法(由戴夫),因为它需要更少的代码.
更新:正如Dave DeLong所指出的,没有必要使用Core Graphics功能.这应该做的伎俩:
[path addClip];
[image drawAtPoint:CGPointZero];
Run Code Online (Sandbox Code Playgroud)