标签:
1 Creates and returns a new UIBezierPath object initialized with a rectangular path. 2 3 + (UIBezierPath *)bezierPathWithRect:(CGRect)rect
1 Creates and returns a new UIBezierPath object initialized with an arc of a circle. 2 3 + (UIBezierPath *)bezierPathWithArcCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise 4 Parameters 5 center 6 Specifies the center point of the circle (in the current coordinate system) used to define the arc. 7 radius 8 Specifies the radius of the circle used to define the arc. 9 startAngle 10 Specifies the starting angle of the arc (measured in radians). 11 endAngle 12 Specifies the end angle of the arc (measured in radians). 13 clockwise 14 The direction in which to draw the arc. 15 Return Value 16 A new path object with the specified arc.
#define pi 3.14159265359 #define DEGREES_TO_RADIANS(degrees) ((pi * degrees)/ 180)
- (void)drawRect:(CGRect)rect { UIColor *color = [UIColor redColor]; [color set]; //设置线条颜色 UIBezierPath* aPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:75 startAngle:0 endAngle:DEGREES_TO_RADIANS(135) clockwise:YES]; aPath.lineWidth = 5.0; aPath.lineCapStyle = kCGLineCapRound; //线条拐角 aPath.lineJoinStyle = kCGLineCapRound; //终点处理 [aPath stroke]; }
- (void)drawRect:(CGRect)rect { UIColor *color = [UIColor redColor]; [color set]; //设置线条颜色 UIBezierPath* aPath = [UIBezierPath bezierPath]; aPath.lineWidth = 5.0; aPath.lineCapStyle = kCGLineCapRound; //线条拐角 aPath.lineJoinStyle = kCGLineCapRound; //终点处理 [aPath moveToPoint:CGPointMake(20, 50)]; [aPath addCurveToPoint:CGPointMake(200, 50) controlPoint1:CGPointMake(110, 0) controlPoint2:CGPointMake(110, 100)]; [aPath stroke]; }
1 // Create the path data 2 CGMutablePathRef cgPath = CGPathCreateMutable(); 3 CGPathAddEllipseInRect(cgPath, NULL, CGRectMake(0, 0, 300, 300)); 4 CGPathAddEllipseInRect(cgPath, NULL, CGRectMake(50, 50, 200, 200)); 5 6 // Now create the UIBezierPath object 7 UIBezierPath* aPath = [UIBezierPath bezierPath]; 8 aPath.CGPath = cgPath; 9 aPath.usesEvenOddFillRule = YES; 10 11 // After assigning it to the UIBezierPath object, you can release 12 // your CGPathRef data type safely. 13 CGPathRelease(cgPath);
Mixing Core Graphics and UIBezierPath
calls
1 UIBezierPath* aPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 300, 300)]; 2 3 // Get the CGPathRef and create a mutable version. 4 CGPathRef cgPath = aPath.CGPath; 5 CGMutablePathRef mutablePath = CGPathCreateMutableCopy(cgPath); 6 7 // Modify the path and assign it back to the UIBezierPath object 8 CGPathAddEllipseInRect(mutablePath, NULL, CGRectMake(50, 50, 200, 200)); 9 aPath.CGPath = mutablePath; 10 11 // Release both the mutable copy of the path. 12 CGPathRelease(mutablePath);
Drawing a path in a view
- (void)drawRect:(CGRect)rect { // Create an oval shape to draw. UIBezierPath* aPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(0, 0, 200, 100)]; // Set the render colors [[UIColor blackColor] setStroke]; [[UIColor redColor] setFill]; CGContextRef aRef = UIGraphicsGetCurrentContext(); // If you have content to draw after the shape, // save the current state before changing the transform //CGContextSaveGState(aRef); // Adjust the view‘s origin temporarily. The oval is // now drawn relative to the new origin point. CGContextTranslateCTM(aRef, 50, 50); // Adjust the drawing options as needed. aPath.lineWidth = 5; // Fill the path before stroking it so that the fill // color does not obscure the stroked line. [aPath fill]; [aPath stroke]; // Restore the graphics state before drawing any other content. //CGContextRestoreGState(aRef); }
标签:
原文地址:http://www.cnblogs.com/H7N9/p/5065287.html