iOS 绘制饼图代码
发布时间:2020-12-16 07:42:45 所属栏目:百科 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 CGContextAddArc(CGContextRef __nullable c,CGFloat x,CGFloat y,CGFloat radius,CGFloat startAngle,CGFloat endAngle,int clockwise) CGFloat degr
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 CGContextAddArc(CGContextRef __nullable c,CGFloat x,CGFloat y,CGFloat radius,CGFloat startAngle,CGFloat endAngle,int clockwise) CGFloat degree=(count/allCount)*(360.f-2*self.dataSource.count); staticinlinefloat radians(double degrees) { return degrees * M_PI/ 180.f; } - (void)drawRect:(CGRect)rect { CGContextRef context=UIGraphicsGetCurrentContext(); //设置半径 CGFloat radius=130.f; if (self.circularRingRadius==0) { self.circularRingRadius=54.f; } CGFloat intRadius=radius-self.circularRingRadius; //设置圆心的坐标 CGFloat centerX=self.bounds.size.width/2.f; CGFloat centerY=self.bounds.size.height/2.f; //设置起始角度 CGFloat pieStart=90.f; //设置旋转方向 int clockwise=0; //1: 顺时针 ; 0:逆时针 //画扇形 if(allCount == 0){ //无资产 CGContextSetFillColorWithColor(context,[HEXCOLOR(0xefeff4) CGColor]); CGContextMoveToPoint(context,centerX,centerY); CGContextAddArc(context,centerY,radius,radians(0),radians(360),clockwise); CGContextClosePath(context); CGContextFillPath(context); }else{ for (int i=0; i<self.degreeArray.count; i++) { CGFloat end=pieStart+[self.degreeArray[i] doubleValue]; if (self.isShowSeperate) { if(i%2==0){ //分割线 UIColor *fillColor=self.colorArray[(int)(i/2)]; CGContextSetFillColorWithColor(context,[fillColor CGColor]); }else{ CGContextSetFillColorWithColor(context,[HEXCOLOR(0xefeff4) CGColor]); } }else{ CGContextSetFillColorWithColor(context,[self.colorArray[i] CGColor]); } NSLog(@"%f",radians(end)); CGContextMoveToPoint(context,centerY); CGContextAddArc(context,radians(pieStart),radians(end),clockwise); CGContextClosePath(context); CGContextFillPath(context); pieStart+=[self.degreeArray[i] doubleValue]; } } //画内圆 CGContextSetFillColorWithColor(context,[[UIColor whiteColor] CGColor]); CGContextMoveToPoint(context,centerY); CGContextAddArc(context,intRadius,radians(360.f),0); CGContextClosePath(context); CGContextFillPath(context); }
原文?
http://www.lvesli.com/?p=339
以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |