Reputation: 291
I an trying to fill this shape. But with my code it fills whole view, not inside shape.
UIBezierPath *shape = [UIBezierPath bezierPathWithRect:self.bounds];
[shape moveToPoint:CGPointMake(self.bounds.size.width*0.15, self.bounds.size.height*0.6)];
[shape addCurveToPoint:CGPointMake(self.bounds.size.width*0.85, self.bounds.size.height*0.4)
controlPoint1:CGPointMake(self.bounds.size.width*0.1, self.bounds.size.height*0.3)
controlPoint2:CGPointMake(self.bounds.size.width*0.6, self.bounds.size.height*0.5)];
[shape addCurveToPoint:CGPointMake(self.bounds.size.width*0.15, self.bounds.size.height*0.6)
controlPoint1:CGPointMake(self.bounds.size.width*0.9, self.bounds.size.height*0.7)
controlPoint2:CGPointMake(self.bounds.size.width*0.4, self.bounds.size.height*0.5)];
[shape closePath];
[[UIColor blueColor] setFill];
[shape fill];
[[UIColor brownColor] setStroke];
[shape stroke];
what's the problem? When I draw triangle or any other shape, it works perfectly.
Upvotes: 1
Views: 907
Reputation: 11217
Try this:
I think you will get that shape only...
UIBezierPath *shape = [[UIBezierPath alloc] init];
[shape moveToPoint:CGPointMake(45,78)];
[shape addCurveToPoint:CGPointMake(67,51)
controlPoint1:CGPointMake(43,78)
controlPoint2:CGPointMake(55,54)];
[shape addCurveToPoint:CGPointMake(144,45)
controlPoint1:CGPointMake(80,49)
controlPoint2:CGPointMake(137,60)];
[shape addCurveToPoint:CGPointMake(143,77)
controlPoint1:CGPointMake(157,34)
controlPoint2:CGPointMake(143,77)];
[shape addCurveToPoint:CGPointMake(43,84)
controlPoint1:CGPointMake(143,77)
controlPoint2:CGPointMake(43,65)];
[shape addCurveToPoint:CGPointMake(43,78)
controlPoint1:CGPointMake(43,103)
controlPoint2:CGPointMake(43,78)];
[shape closePath];
[[UIColor blueColor] setFill];
[shape fill];
[[UIColor brownColor] setStroke];
shape.lineWidth = 1;
[shape stroke];
Change CGPoint depend upon your shape....
If still more confusion just try this tool and get your code by drawing shapes...
Tool Name: PaintCode (http://www.paintcodeapp.com/)
Download Link: http://www.paintcodeapp.com/wp-content/uploads/2013/10/paintcode-trial-1-3-3.zip
Upvotes: 0
Reputation: 7710
UIBezierPath *shape = [UIBezierPath bezierPathWithRect:self.bounds];
That's the problem. You are creating a path with the view's bounds. Use UIBezierPath *shape = [[UIBezierPath alloc] init];
instead.
Upvotes: 1