ios 用程序绘制饼图的demo(5)
//float starty1 = stary + spaceHeight;
float endy1 = endy + spaceHeight;
if(endAngle < K_PI)
{
}
//只有弧度《 3.14 的才会画前面的厚度
else if(startAngle < K_PI)
{
endAngle = K_PI;
endx = 10;
endy1 = 230+spaceHeight;
}
else
break;
//CGContextSetBlendMode(context, kCGBlendModeMultiply);
//绘制厚度
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, nil, starx, stary);
CGPathAddArc(path, nil, 160, 230, 150, startAngle, endAngle, 0);
CGPathAddLineToPoint(path, nil, endx, endy1);
CGPathAddArc(path, nil, 160, 230 + spaceHeight, 150, endAngle, startAngle, 1);
CGContextAddPath(context, path);
[[colorArr objectAtIndex:i % [valueArr count]] setFill];
[[UIColor colorWithWhite:0.9 alpha:1.0] setStroke];
CGContextDrawPath(context, kCGPathFill);
[[UIColor colorWithWhite:0.1 alpha:0.4] setFill];
CGContextAddPath(context, path);
CGContextDrawPath(context, kCGPathFill);
}
//整体渐变
CGFloat componets [] = {0.0, 0.0, 0.0, 0.5,0.0,0.0,0.0,0.1};
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorspace, componets, nil, 2);
CGContextDrawRadialGradient(context, gradient, CGPointMake(160,230), 0, CGPointMake(160,230), 150, 0 );
CFRelease(colorspace);
CGGradientRelease(gradient);
CGContextRestoreGState(context);
//绘制文字
for(int i = 0; i< [valueArr count]; i++)
{
float origionx = 50 ;
float origiony = i * 30 + 200;
[[colorArr objectAtIndex:i % [valueArr count]] setFill];
CGContextFillRect(context, CGRectMake(origionx, origiony, 20, 20));
CGContextDrawPath(context, kCGPathFill);
if(i< [titleArr count])
{
NSString *title = [ titleArr objectAtIndex:i];
[title drawAtPoint:CGPointMake(origionx + 50, origiony) withFont:[UIFont systemFontOfSize:16]];
相关新闻>>
- 发表评论
-
- 最新评论 更多>>