Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to fill a UIBezierPath with a pattern image?

Tags:

ios

iphone

I'm trying do draw a rounded rect filled with a pattern image (the pattern image should be repeated to fill the rect), is there a way to do that using UIBezierPath? Possibly I would like to add a shadow to the border of the rect. Thanks

like image 422
Emanuele Fumagalli Avatar asked Jan 17 '23 16:01

Emanuele Fumagalli


2 Answers

Is there anything you tried already?

First thing that comes to mind would be:

UIImage *patternImg = [UIImage imageNamed:@"SomePattern.png"];
UIColor *fill = [UIColor colorWithPatternImage:patternImg];
[path fill];

Another option would be to draw a rectangle that fits your path, fill that using your pattern color, and clip that using your path.

like image 134
Joris Kluivers Avatar answered Feb 11 '23 17:02

Joris Kluivers


have you tried [[UIColor colorWithPatternImage:YOUR_UI_IMAGE] setFill]?

like image 43
Marcelo Alves Avatar answered Feb 11 '23 17:02

Marcelo Alves