1.基本形状
#import "DrawView.h"
@implementation DrawView
-(void)drawRect:(CGRect)rect{
[self drawLoop];
}
-(void)drawLoop
{
UIBezierPath *path = [UIBezierPath bezierPath];
CGPoint center = CGPointMake(100, 100);
[path addArcWithCenter:center radius:50 startAngle:0 endAngle:M_PI * 2 clockwise:YES];
[path addLineToPoint:center];
[path closePath];
path.lineWidth = 10;
[[UIColor greenColor] setStroke];
[path stroke];
[[UIColor redColor] setFill];
[path fill];
}
-(void)drawFan{
UIBezierPath *path = [UIBezierPath bezierPath];
CGPoint center = CGPointMake(100, 100);
[path addArcWithCenter:center radius:50 startAngle:0 endAngle:M_PI_2 clockwise:YES];
[path addLineToPoint:center];
[path closePath];
[[UIColor redColor] set];
[path fill];
}
-(void)drawCircle{
UIBezierPath *path = [UIBezierPath bezierPath];
[path addArcWithCenter:CGPointMake(100, 100) radius:50 startAngle:0 endAngle:M_PI * 2 clockwise:YES];
[[UIColor redColor] setStroke];
[path stroke];
}
-(void)drawRect{
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(20, 20, 100, 100)];
path.lineWidth = 20;
path.lineJoinStyle = kCGLineJoinRound;
[[UIColor redColor] setStroke];
[path stroke];
}
-(void)drawQuadCurve{
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(10, 100)];
[path addQuadCurveToPoint:CGPointMake(110, 100) controlPoint:CGPointMake(50, 10)];
[path stroke];
}
-(void)drawLine1{
CGContextRef ctx = UIGraphicsGetCurrentContext();
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointZero];
[path addLineToPoint:CGPointMake(100, 100)];
CGContextSetLineWidth(ctx, 10);
CGContextAddPath(ctx, path.CGPath);
CGContextStrokePath(ctx);
}
-(void)drawLine2{
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointZero];
[path addLineToPoint:CGPointMake(100, 100)];
path.lineWidth = 20;
path.lineCapStyle = kCGLineCapRound;
[path stroke];
}
@end