android饼状图简书,IOS 饼状图简单画法

效果

309db0528f79

ios饼状图简单画法-效果图

重写 - (void)drawRect:(CGRect)rect { //... }

线宽,用线去涂色!

CGFloat viewHalfWidth = rect.size.width/2.0;

CGFloat lineWidth = viewHalfWidth;

内部想预留空间减去相应长度即可

CGFloat insideCircleWidth = 50;

lineWidth = viewHalfWidth - insideCircleWidth;

半径、中心点

CGFloat circleRadius = viewHalfWidth - lineWidth/2;

CGPoint circleCenterPoint = CGPointMake(viewHalfWidth, viewHalfWidth);

必要的数据

NSArray*colorArray = [NSArray arrayWithObjects:[UIColor redColor],  [UIColor orangeColor], [UIColor brownColor], [UIColor cyanColor], nil];

NSArray*percentArray = [NSArray arrayWithObjects:@(.1), @(.2), @(.3), @(.4), nil];

准备好之后开始画了!

CGContextRef pieViewContext = UIGraphicsGetCurrentContext();

CGFloat startAngel = 0;

CGFloat endAngel;

for (int i =0; i < colorArray.count; i++) {

endAngel = startAngel + M_PI*2*percentArray[i].floatValue;

CGContextAddArc(pieViewContext, circleCenterPoint.x, circleCenterPoint.y, circleRadius, startAngel, endAngel, NO);

CGContextSetStrokeColorWithColor(pieViewContext, colorArray[i].CGColor);

CGContextSetLineWidth(pieViewContext, lineWidth);

CGContextStrokePath(pieViewContext);

startAngel = endAngel;

}最后,发挥自己的想象,抽离出其中变量,满足自己的具体需求!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值