IOS基础之绘图函数的使用
#import "HMView.h"
@implementation HMView
- (void)drawRect:(CGRect)rect {
[self test11];
}
-(void)test11{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextAddArc(ctx, 150, 150, 100, 0, 2*M_PI, 1);
CGContextStrokePath(ctx);
}
-(void)test10{
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:0 endAngle:2*M_PI - M_PI_2 clockwise:YES];
[path stroke];
}
-(void)test9{
CGContextRef ctx=UIGraphicsGetCurrentContext();
CGContextAddEllipseInRect(ctx, CGRectMake(10, 10, 150, 100));
CGContextStrokePath(ctx);
}
-(void)test8{
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 200, 200)];
[path stroke];
}
-(void)test7{
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 100, 100, 100) cornerRadius:50];
[path stroke];
}
-(void)test6{
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(100, 100, 100, 100)];
[path stroke];
}
-(void)test5{
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(50, 50)];
[path addLineToPoint:CGPointMake(100, 100)];
[path stroke];
}
-(void)test4{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 50, 50);
CGPathAddLineToPoint(path, NULL, 100, 100);
UIBezierPath *path1 = [UIBezierPath bezierPathWithCGPath:path];
[path1 addLineToPoint:CGPointMake(150, 50)];
CGContextAddPath(ctx, path1.CGPath);
CGContextStrokePath(ctx);
}
-(void)test3{
CGContextRef ctx = UIGraphicsGetCurrentContext();
UIBezierPath *path = [[UIBezierPath alloc] init];
[path moveToPoint:CGPointMake(50, 50)];
[path addLineToPoint:CGPointMake(100, 250)];
CGContextAddPath(ctx, path.CGPath);
CGContextStrokePath(ctx);
}
-(void)test2{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 50, 50);
CGPathAddLineToPoint(path, NULL, 100, 200);
CGContextAddPath(ctx, path);
CGContextStrokePath(ctx);
}
-(void)test1{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(ctx, 50, 50);
CGContextAddLineToPoint(ctx, 100, 100);
CGContextAddLineToPoint(ctx, 150, 50);
CGContextMoveToPoint(ctx, 50, 200);
CGContextAddLineToPoint(ctx, 200, 200);
CGContextStrokePath(ctx);
}
@end