2019独角兽企业重金招聘Python工程师标准>>>

1.使用 UIGraphicsGetCurrentContext() 画圆

CGContextAddArc(<#CGContextRef  _Nullable c#>, <#CGFloat x#>, <#CGFloat y#>, <#CGFloat radius#>, <#CGFloat startAngle#>, <#CGFloat endAngle#>, <#int clockwise#>)

x,y为圆点坐标,radius半径,startAngle为开始的弧度,endAngle为 结束的弧度,clockwise 0为顺时针,1为逆时针。

-(void)drawRect:(CGRect)rect{CGFloat lineWidth = 12;NSInteger sleepScore = arc4random() % 101;//定义一个不透明类型的Quartz 2D绘画环境,相当于一个画布CGContextRef context = UIGraphicsGetCurrentContext();[[UIColor whiteColor] set];CGContextFillRect(context, rect);//有值圆CGFloat scoreLine = sleepScore/100.0;Log(@"sleepScore %ld %f",sleepScore,scoreLine);CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"#48BBAD"].CGColor);CGContextSetLineWidth(context, lineWidth);CGContextAddArc(context, rect.size.width/2,rect.size.height, rect.size.width/2-lineWidth/2, -M_PI, -M_PI/4, 0);// 0为顺时针,1为逆时针CGContextDrawPath(context, kCGPathStroke);/*写分数*/CGFloat fontSize = (rect.size.height-lineWidth)*0.7;CGRect scoreRect = CGRectMake(rect.size.width/2-fontSize, rect.size.height-fontSize, fontSize*2, fontSize);[self drawTextWithContent:@"100" WithFontSize:fontSize WithWeight:1 withTextColor:[UIColor blackColor] withRect:scoreRect withAlignment:NSTextAlignmentCenter];
}
-(void)drawTextWithContent:(NSString *)text WithFontSize:(CGFloat)fontSize WithWeight:(CGFloat)weight withTextColor:(UIColor *)textColor withRect:(CGRect)rect withAlignment:(NSTextAlignment)alignment{//    Log(@"fontSize:%f",fontSize);NSMutableDictionary *attributesDic = [NSMutableDictionary dictionary];attributesDic[NSFontAttributeName] = [UIFont systemFontOfSize:fontSize weight:weight];attributesDic[NSForegroundColorAttributeName] = textColor;//段落格式NSMutableParagraphStyle *textStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];textStyle.lineBreakMode = NSLineBreakByWordWrapping;textStyle.alignment = alignment;//对齐方式attributesDic[NSParagraphStyleAttributeName] = textStyle;[text drawInRect:rect withAttributes:attributesDic];
}

转载于:https://my.oschina.net/u/2365397/blog/1583670

iOS绘圆形图-CGContextAddArc各参数说明相关推荐

  1. ios 裁剪圆形头像_IOS_iOS如何裁剪圆形头像,本文实例为大家介绍了iOS裁剪 - phpStudy...

    iOS如何裁剪圆形头像 本文实例为大家介绍了iOS裁剪圆形头像的详细代码,供大家参考,具体内容如下 - (void)viewDidLoad { [super viewDidLoad]; //加载图片 ...

  2. R语言绘制箱图(Base R and ggplot2)

    R语言绘制箱图 目录 R语言绘制箱图 R原生绘制箱图 ggplot2绘制箱图 箱图boxplot(有时称为Box-and-Whitker plot)是一种显示

  3. ios html gif 显示,iOS中gif图的显示方法示例

    iOS中gif图的显示方法示例 发布时间:2020-09-19 06:15:42 来源:脚本之家 阅读:86 作者:蓝光95 一.前言 iOS开发中,大部分时候我们显示一张静态图就可以了,但是有的时候 ...

  4. Glide加载常用类型图片(带白色边框的圆形图、圆角矩形图片、圆形图片)

    一:依赖包: Glide_github implementation 'com.github.bumptech.glide:glide:4.8.0' annotationProcessor 'com. ...

  5. pyecharts画饼形图,圆形图,环形图(含百分比显示)【python干货】

    很多做数据分析可视化的朋友总会遇到一些烦恼,用pyecharts绘制饼形图(圆形图)的时候,总会报错. 废话不多说,下面跟着小编上车吧,教你用pyecharts绘制饼形图(圆形图),环形图从小白到精通 ...

  6. PPT绘论文图之导出分辨率

    PPT绘论文图之导出分辨率 步骤 验证 步骤 关闭所有office软件; 按下WIN+R,输入regedit; 找到以下路径:计算机\HKEY_CURRENT_USER\SOFTWARE\Micros ...

  7. Android中圆形图的几种实现方式

    在Android开发中,圆形图片是很常见的,例如淘宝的宝贝,QQ的联系人头像等都是圆形的图片, 但是Android原生的ImageView又不能显示圆形的图片,这就需要我们自己去实现一个圆形图了 一. ...

  8. Glide 使用 +圆形图+圆角图

    Glide3.0新增 1.GIF Animated GIF decoding - Just use the same Glide.with(...).load(...) call and if the ...

  9. Echart饼图-圆形图修改重新绘制

    首先看看默认效果: 代码如下: option = {tooltip: {trigger: 'item'},legend: {top: '5%',left: 'center'},series: [{na ...

最新文章

  1. Lintcode: Kth Smallest Number in Sorted Matrix
  2. html中怎么显示错误信息,在html中显示为内嵌错误的文本
  3. 【多视图几何】TUM 课程 第2章 刚体运动
  4. 认真测试直播软件,直播这么火,你知道怎么测试直播软件吗?
  5. zabbix增加手机端4个url地址的返回值
  6. 给定数组,去掉0元素后将剩下的元素赋给新的数组
  7. NOIP2016-D2-T2 蚯蚓(单调队列)
  8. SAP License:PS的进度管理流程
  9. 【Q】【POJ 2560】【POJ 2031】
  10. Tomcat Server的结构图
  11. [leetcode]5354. 通知所有员工所需的时间
  12. JAVA 实现生命游戏
  13. 计算机查看iphone照片,苹果手机上的图片如何在电脑上查看
  14. Linux vim 编辑文件底部显示[converted]解决办法
  15. 201621123068 Week02-Java基本语法与类库
  16. Learning Continuous Image Representation with Local Implicit Image Function解读
  17. java提升的计划书
  18. IDEA中修改html页面后在浏览器不生效的解决方法
  19. 高中计算机教师研究方向,高中信息技术教师专业知识研究
  20. 深度|从一个故事说起,谈谈企业应用架构的演变史

热门文章

  1. 递归-输出字符串所有的组合情况(代码、分析、汇编)
  2. python安全攻防---信息收集---IP查询
  3. php数组的下标、extract函数
  4. spring的Bean属性
  5. 142. 环形链表 II golang
  6. c++的vector容器
  7. MTD和 uboot中的bootargs 下属 mtdparts
  8. S3C2440时钟体系
  9. 【C++ Priemr | 15】面向对象程序设计
  10. Java开发知识体系!我用2个月的时间破茧成蝶