ios 在UIView上画图,线条
1.画线条(实线,虚线)
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
[self drawXLine:context rect:rect];
[self drawLegend:context rect:rect];
}
-(CGContextRef)drawXLine:(CGContextRef)context rect:(CGRect)rect {CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);//float partren[] = {2,3};//CGContextSetLineDash(context, 0,partren , 2); //画虚线 CGContextMoveToPoint(context, 10, 0);CGContextAddLineToPoint(context, 0, 100);CGContextStrokePath(context);return context; }
2.画图例说明
//画图例说明 -(void)drawLegend:(CGContextRef)context rect:(CGRect)_rect {CGSize myShadowOffset = CGSizeMake (2, 2);//矩形和阴影的位置 CGContextSaveGState(context);CGContextSetFillColorWithColor(context, [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1].CGColor);CGContextSetShadow (context, myShadowOffset, 2); //背景的阴影CGContextFillRect(context, CGRectMake(self.frame.size.width/2-100, [UIScreen mainScreen].bounds.size.height-80, 200, 25.0));NSArray *groupTitle = [NSArray arrayWithObjects:@"提出问题数量",@"方案采纳数量", nil];int legendCount = [groupTitle count];int stepWidth = 15;for (int i = 0; i < legendCount; i++) {if (i == 0){//设定第一个图例的颜色CGContextSetFillColorWithColor(context, [UIColor colorWithRed:64.0/255.0 green:104.0/255.0 blue:168.0/255.0 alpha:1.0].CGColor);}else {//设定第二个图例的颜色CGContextSetFillColorWithColor(context, [UIColor colorWithRed:240.0/255.0 green:152.0/255.0 blue:56.0/255.0 alpha:1.0].CGColor);}CGContextSetShadow (context, myShadowOffset, 1);CGContextFillRect(context, CGRectMake(stepWidth + 50, [UIScreen mainScreen].bounds.size.height-72, 10, 10)); //小方块的大小以及位置 UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(stepWidth+65, [UIScreen mainScreen].bounds.size.height-76, _rect.size.width, 18)]; //声明UIlbel并指定其位置和长宽label2.backgroundColor = [UIColor clearColor]; //设置label的背景色,这里设置为透明色。label2.font = [UIFont fontWithName:@"Helvetica-Bold" size:12]; //设置label的字体和字体大小。//label2.transform = CGAffineTransformMakeRotation(0.1); //设置label的旋转角度label2.text = [groupTitle objectAtIndex:i]; //设置label所显示的文本label2.textColor = [UIColor blackColor]; //设置文本的颜色label2.textAlignment =NSTextAlignmentLeft; //设置文本在label中显示的位置,这里为居中。 [self addSubview:label2];stepWidth += 100;}CGContextRestoreGState(context); }
---恢复内容结束---
转载于:https://www.cnblogs.com/lihaibo-Leao/p/3260032.html
ios 在UIView上画图,线条相关推荐
- iOS获取UIView上某点的颜色值
项目需求中遇到获取UIView上某个坐标点的RGB颜色值的需求,现在把自己找到的解决方案简单总结记录一下,遇到了下面的情况: 不可移动的UIView 旋转式的UIView 滑条式的UIView 不可移 ...
- ios view 切上部分圆角_iOS - 指定UIView的某几个角为圆角
如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架).而若要指定某几个角(小于4)为圆角而别的不变时 ...
- iOS:Github上的开源项目集合
转载地址:http://blog.csdn.NET/hbblzjy/article/details/52083919 下拉刷新 EGOTableViewPullRefresh - 最早的下拉刷新控件. ...
- 怎么在谷歌地图上画图_如何在Google地图上规划具有多个目的地的公路旅行
怎么在谷歌地图上画图 Whether you're planning a day out on the town, or want to orchestrate the perfect road tr ...
- 疯狂iOS 讲义(上) Objective-C 2.0与iPhone/iPad应用开发基础(国内首部iOS 7相关著作,小伙伴们,学好iPhone/iPad应用开发,我们一起做土豪吧)
疯狂iOS 讲义(上) Objective-C 2.0与iPhone/iPad应用开发基础(国内首部iOS 7相关著作,小伙伴们,学好iPhone/iPad应用开发,我们一起做土豪吧) 李刚 编 IS ...
- Vue:Vue和ECharts,在Vue上进行可视化处理,在Vue上画图
Vue:Vue和ECharts,在Vue上进行可视化处理,在Vue上画图 一.预科知识 Vue CLI ECharts 二.资源 在Vue中使用echarts 如何在 Vue 项目中使用 echart ...
- 企业应用程序部署在iOS 7.1上不起作用
本文翻译自:Enterprise app deployment doesn't work on iOS 7.1 We distribute apps via an Enterprise account ...
- UIView上的控件使用push方法跳转
有时候在项目中,为了保持前后页面的推进方式跳转方式一致,会在通过UIview上的控件跳到另一个Controller上,所以,这时候就需要用到这种方式了,当然,present方法可以实现跳转但是样式可能 ...
- java 在底图上绘制线条_使用底图和geonamescache绘制k表示聚类
java 在底图上绘制线条 This is the third of four stories that aim to address the issue of identifying disease ...
最新文章
- Windows Azure Storage (25) Azure Append Blob
- 两个大炸弹:清华大学医学院院长董晨院士回应“24篇论文质疑”;南开校长,曹雪涛团队12篇论文被正式调查“可信性”...
- 德富莱智能抹墙机器人_深圳智能制造应急生产联盟成立,大咖共探机器人行业新机遇...
- DL之DNN:利用MultiLayerNet模型【6*100+ReLU+SGD,weight_decay】对Mnist数据集训练来抑制过拟合
- 计算机学硕和专硕编码,2018考研报名:学会从专业代码判断学硕还是专硕
- 完成一个分析H264码流的工具
- 【java】java 并发编程 CyclicBarrier 源码分析
- 一次Linux内核内存泄露实例分析
- php 3.2 下载,PHPWind
- 物联网工程导论 简单整理
- 【模拟电子技术Analog Electronics Technology 14】——集成运放中的单元电路 之 集成运放的输入级:长尾式差放各种接法的参数分析
- 奖补多的2022年合肥高新区高成长企业申报时间入选范围及申报条件材料
- CityEngine2016-学习笔记(1)Writing Rules
- 达梦数据库安装及连接
- 微型SR602人体感应模块原理图
- PHP实现带有验证码的登陆注册
- 【RFC5382 TCP 的 NAT 行为要求】(翻译)
- 用Python自动化操作PPT,看完这篇文章就够了!
- MySQL学习记录(11.9更新)
- 暗影精灵系列更换电池后电池无法充满无法充电解决方案