iOS绘圆形图-CGContextAddArc各参数说明
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各参数说明相关推荐
- ios 裁剪圆形头像_IOS_iOS如何裁剪圆形头像,本文实例为大家介绍了iOS裁剪 - phpStudy...
iOS如何裁剪圆形头像 本文实例为大家介绍了iOS裁剪圆形头像的详细代码,供大家参考,具体内容如下 - (void)viewDidLoad { [super viewDidLoad]; //加载图片 ...
- R语言绘制箱图(Base R and ggplot2)
R语言绘制箱图 目录 R语言绘制箱图 R原生绘制箱图 ggplot2绘制箱图 箱图boxplot(有时称为Box-and-Whitker plot)是一种显示
- ios html gif 显示,iOS中gif图的显示方法示例
iOS中gif图的显示方法示例 发布时间:2020-09-19 06:15:42 来源:脚本之家 阅读:86 作者:蓝光95 一.前言 iOS开发中,大部分时候我们显示一张静态图就可以了,但是有的时候 ...
- Glide加载常用类型图片(带白色边框的圆形图、圆角矩形图片、圆形图片)
一:依赖包: Glide_github implementation 'com.github.bumptech.glide:glide:4.8.0' annotationProcessor 'com. ...
- pyecharts画饼形图,圆形图,环形图(含百分比显示)【python干货】
很多做数据分析可视化的朋友总会遇到一些烦恼,用pyecharts绘制饼形图(圆形图)的时候,总会报错. 废话不多说,下面跟着小编上车吧,教你用pyecharts绘制饼形图(圆形图),环形图从小白到精通 ...
- PPT绘论文图之导出分辨率
PPT绘论文图之导出分辨率 步骤 验证 步骤 关闭所有office软件; 按下WIN+R,输入regedit; 找到以下路径:计算机\HKEY_CURRENT_USER\SOFTWARE\Micros ...
- Android中圆形图的几种实现方式
在Android开发中,圆形图片是很常见的,例如淘宝的宝贝,QQ的联系人头像等都是圆形的图片, 但是Android原生的ImageView又不能显示圆形的图片,这就需要我们自己去实现一个圆形图了 一. ...
- Glide 使用 +圆形图+圆角图
Glide3.0新增 1.GIF Animated GIF decoding - Just use the same Glide.with(...).load(...) call and if the ...
- Echart饼图-圆形图修改重新绘制
首先看看默认效果: 代码如下: option = {tooltip: {trigger: 'item'},legend: {top: '5%',left: 'center'},series: [{na ...
最新文章
- Lintcode: Kth Smallest Number in Sorted Matrix
- html中怎么显示错误信息,在html中显示为内嵌错误的文本
- 【多视图几何】TUM 课程 第2章 刚体运动
- 认真测试直播软件,直播这么火,你知道怎么测试直播软件吗?
- zabbix增加手机端4个url地址的返回值
- 给定数组,去掉0元素后将剩下的元素赋给新的数组
- NOIP2016-D2-T2 蚯蚓(单调队列)
- SAP License:PS的进度管理流程
- 【Q】【POJ 2560】【POJ 2031】
- Tomcat Server的结构图
- [leetcode]5354. 通知所有员工所需的时间
- JAVA 实现生命游戏
- 计算机查看iphone照片,苹果手机上的图片如何在电脑上查看
- Linux vim 编辑文件底部显示[converted]解决办法
- 201621123068 Week02-Java基本语法与类库
- Learning Continuous Image Representation with Local Implicit Image Function解读
- java提升的计划书
- IDEA中修改html页面后在浏览器不生效的解决方法
- 高中计算机教师研究方向,高中信息技术教师专业知识研究
- 深度|从一个故事说起,谈谈企业应用架构的演变史