Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fill an UIBezierPath with a UIImage

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.

like image 453
Kristian Flatheim Jensen Avatar asked Mar 09 '11 17:03

Kristian Flatheim Jensen


1 Answers

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];
like image 175
Daniel Dickison Avatar answered Oct 04 '22 12:10

Daniel Dickison