使用UIImage填充UIBezierPath [英] Fill an UIBezierPath with a UIImage
本文介绍了使用UIImage填充UIBezierPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有圆形的UIBezierpath:
UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:100];
但是我想用UIImage填充圆圈在圈子内)
最好的问候
Kristian
编辑:
$ b $感谢丹尼尔和Dave的优秀答案:D救了我很多麻烦; D解决方案:
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextAddPath(ctx,path.CGPath);
CGContextClip(ctx);
和:
path.addClip;
这两个都很完美,但我最后使用最后一个方法(Dave),因为它需要更少的代码。
解决方案
更新:正如Dave DeLong指出的,没有必要使用Core Graphics函数。这应该做的诀窍:
[path addClip];
[image drawAtPoint:CGPointZero];
I got an UIBezierpath with a circle shape:
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:100];
But then i want to fill the circle with an UIImage (show only a portion of the image which is inside the circle)
Best Regards Kristian
Edit:
Thanks to Daniel and Dave for excellent answers :D saved me a lot of trouble ;D
The solutions:
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextAddPath(ctx, path.CGPath);
CGContextClip(ctx);
and:
path.addClip;
Both works perfectly but i ended up using the last method (by Dave) because it required less code.
解决方案
Update: as Dave DeLong points out, there's no need to use Core Graphics functions. This should do the trick:
[path addClip];
[image drawAtPoint:CGPointZero];
这篇关于使用UIImage填充UIBezierPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文