UIBezierPath define a path consisting of straight and curved line segment and render the path in custom views. We can use this for specify the geometry of path, path can define simple shapes such as rectangle, oval, arc or can define complex polygons.For more details about UIBezierPath Click Here.
I am going to draw a custom view with transparent oval.I will use UIBenzierPath fro achieving result.
First create a SubClass of UIView.
Ex. named sub class to CustomView
Inside drawRect: method of CustomView.m
- (void)drawRect:(CGRect)rect {
// Drawing code
//First Create path for Oval
UIBezierPath *apath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(5, 5, self.frame.size.width-10, self.frame.size.height-10)];
//Create another path
UIBezierPath *clipPath = [ UIBezierPath bezierPathWithRect:CGRectInfinite];
//Append both path
[clipPath appendPath:apath];
clipPath.usesEvenOddFillRule = YES; //
CGContextSaveGState(UIGraphicsGetCurrentContext());
[clipPath addClip];
CGContextSaveGState(UIGraphicsGetCurrentContext());
[[UIColor orangeColor] setFill];
[[UIColor blackColor] setStroke];
clipPath.lineWidth = 2;
[clipPath stroke];
[clipPath fill];
}
I am going to draw a custom view with transparent oval.I will use UIBenzierPath fro achieving result.
First create a SubClass of UIView.
Ex. named sub class to CustomView
Inside drawRect: method of CustomView.m
- (void)drawRect:(CGRect)rect {
// Drawing code
//First Create path for Oval
UIBezierPath *apath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(5, 5, self.frame.size.width-10, self.frame.size.height-10)];
//Create another path
UIBezierPath *clipPath = [ UIBezierPath bezierPathWithRect:CGRectInfinite];
//Append both path
[clipPath appendPath:apath];
clipPath.usesEvenOddFillRule = YES; //
usesEvenOddFillRule property is used to determine whether the even-odd or non-zero rule is used to determine the area enclosed by the path.
CGContextSaveGState(UIGraphicsGetCurrentContext());
[clipPath addClip];
CGContextSaveGState(UIGraphicsGetCurrentContext());
[[UIColor orangeColor] setFill];
[[UIColor blackColor] setStroke];
clipPath.lineWidth = 2;
[clipPath stroke];
[clipPath fill];
}
No comments:
Post a Comment