Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 用UIImage填充UIBezierPath_Objective C_Cocoa - Fatal编程技术网

Objective c 用UIImage填充UIBezierPath

Objective c 用UIImage填充UIBezierPath,objective-c,cocoa,Objective C,Cocoa,我得到了一个圆形的UIBezierpath: UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:100]; 但是我想用UIImage来填充这个圆(只显示圆内的一部分图像) 致意 克里斯蒂安 编辑: 感谢丹尼尔和戴夫的出色回答:D帮我省去了很多麻烦;D 解决办法: CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextAddP

我得到了一个圆形的UIBezierpath:

UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:100];
但是我想用UIImage来填充这个圆(只显示圆内的一部分图像)

致意 克里斯蒂安

编辑: 感谢丹尼尔和戴夫的出色回答:D帮我省去了很多麻烦;D

解决办法:

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextAddPath(ctx, path.CGPath);
CGContextClip(ctx);
以及:


这两种方法都能很好地工作,但我最终使用了最后一种方法(由Dave提出),因为它需要的代码更少。

更新:正如Dave DeLong指出的,没有必要使用核心图形功能。这应该可以做到:

[path addClip];
[image drawAtPoint:CGPointZero];

您可能需要一个蒙面图像,该图像应该在没有bezier path?+1的情况下完成,尽管您不需要使用CoreGraphics来完成此操作。您可以使用
-[UIImage draw….]
-[UIBezierPath addClip]
来完成此操作。打电话给Dave很好--我没有注意到
addClip
方法。更新了显示UIKit实现的答案。
[path addClip];
[image drawAtPoint:CGPointZero];