Fill an UIBezierPath with a UIImage

安稳与你 提交于 2020-02-19 05:02:08

问题


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.


回答1:


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];


来源:https://stackoverflow.com/questions/5249844/fill-an-uibezierpath-with-a-uiimage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!