小编Kri*_*sen的帖子

使用UIImage填充UIBezierPath

我有一个圆形的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)

两者都很完美,但我最终使用了最后一种方法(由戴夫),因为它需要更少的代码.

cocoa objective-c

6
推荐指数
1
解决办法
4976
查看次数

标签 统计

cocoa ×1

objective-c ×1