ios 贝塞尔画图
CGContextRef context = UIGraphicsGetCurrentContext();
//写文字
CGContextSetRGBFillColor(context, 1, 0, 0, 1.0);//设置填充颜色
UIFont *font = [UIFont boldSystemFontOfSize:15.0];
// NSString *str = @"圆";
// [str drawInRect:<#(CGRect)#> withAttributes:<#(NSDictionary *)#>];
//边框圆
CGContextSetRGBStrokeColor(context, 1, 1, 1, 1.0);//画笔颜色
CGContextSetLineWidth(context, 1.0);//线的宽度
CGContextAddArc(context, 50, 100, 20, 0, 2*M_PI, 0);
CGContextDrawPath(context, kCGPathStroke);//绘制路径
//填充圆
CGContextAddArc(context, 120, 100, 25, 2*M_PI, 0, 0);//添加一个圆
CGContextDrawPath(context, kCGPathFill);//绘制填充
//填充圆 有边框
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetLineWidth(context, 3.0);
CGContextAddArc(context, 200, 100, 30, 0, 2*M_PI, 0);
//kCGPathFill填充非零绕数规则,kCGPathEOFill表示用奇偶规则,kCGPathStroke路径,kCGPathFillStroke路径填充,kCGPathEOFillStroke表示描线,不是填充
CGContextDrawPath(context, kCGPathFillStroke);
//画线
CGPoint aPoints[2];
aPoints[0] = CGPointMake(0, 0);
aPoints[1] = CGPointMake(self.frame.size.width, self.frame.size.height);
CGContextAddLines(context, aPoints, 2);
CGContextDrawPath(context, kCGPathStroke);
//画弧
CGContextSetRGBStrokeColor(context, 1, 1, 0.5, 1.0);
CGContextMoveToPoint(context, 50, 200);
CGContextAddArcToPoint(context, 58, 180, 66, 200, 10);
CGContextStrokePath(context);
//画矩形
CGContextStrokeRect(context, CGRectMake(50, 250, 50, 50));
CGContextFillRect(context, CGRectMake(110, 250, 50, 50));
//矩形 并填充颜色
CGContextSetLineWidth(context, 2.0);
CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor);
CGContextAddRect(context, CGRectMake(200, 250, 50, 50));
CGContextDrawPath(context, kCGPathFillStroke);
//第一种填充方式
CAGradientLayer *gradient1 = [CAGradientLayer layer];
gradient1.frame = CGRectMake(50, 320, 60, 30);
gradient1.colors = [NSArray arrayWithObjects:(id)[UIColor whiteColor].CGColor,(id)[UIColor grayColor].CGColor,(id)[UIColor blackColor].CGColor,(id)[UIColor yellowColor].CGColor,(id)[UIColor blueColor].CGColor,(id)[UIColor redColor].CGColor,(id)[UIColor greenColor].CGColor,(id)[UIColor orangeColor].CGColor,(id)[UIColor brownColor].CGColor, nil];
[self.layer insertSublayer:gradient1 atIndex:0];
//第二种填充方式
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
CGFloat colors[] =
{
1,1,1, 1.00,
1,1,0, 1.00,
1,0,1, 1.00,
0,1,1, 1.00,
0,0,1, 1.00,
1,0,0, 1.00,
0,1,0, 1.00,
0,0,0, 1.00,
};
CGGradientRef gradient = CGGradientCreateWithColorComponents(rgb, colors, nil, sizeof(colors)/(sizeof(colors[0])*4));
CGColorSpaceRelease(rgb);
CGContextSaveGState(context);
CGContextMoveToPoint(context, 150, 320);
CGContextAddLineToPoint(context, 170, 320);
CGContextAddLineToPoint(context, 170, 350);
CGContextAddLineToPoint(context, 150, 350);
CGContextClip(context);
CGContextDrawLinearGradient(context, gradient, CGPointMake(100, 320), CGPointMake(130, 350), kCGGradientDrawsAfterEndLocation);
CGContextRestoreGState(context);