1、相关简介

  1.1、iOS之UIBezierPath贝塞尔曲线属性简介

  1.2、iOS之CAShapeLayer属性简介

2、绘制曲线

  2.1、方法详解

- (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint;

  追加一条二次贝塞尔曲线,结束点是endPoint,曲线偏向controlPoint控制点!  

  2.2、绘制曲线

//绘制曲线
- (void)drawView{
UIBezierPath *path = [UIBezierPath bezierPath];
DrawModel *firstModel = [self.dataArr firstObject];
CGPoint firstPoint = firstModel.currPoint;
[path moveToPoint:firstPoint];
if (self.dataArr.count<) {
return;
}
for (int i=; i<self.dataArr.count; i++) {
DrawModel *seconModel = self.dataArr[i];
CGPoint secondPoint = seconModel.currPoint;
//中心点
CGPoint midPoint = [self getMindPointWithFirstPoint:firstPoint secondPoint:secondPoint];
//第一个点都是中心点,为了绘制两点之间有弧度
[path addQuadCurveToPoint:midPoint controlPoint:[self getControlPointWithFirstPoint:midPoint SecondPoint:firstPoint]];
[path addQuadCurveToPoint:secondPoint controlPoint:[self getControlPointWithFirstPoint:midPoint SecondPoint:secondPoint]]; firstPoint = secondPoint;
}
CAShapeLayer *layer = [CAShapeLayer layer];
layer.lineWidth = ;
layer.strokeColor = [UIColor redColor].CGColor;
layer.fillColor = [UIColor clearColor].CGColor;
layer.path = [path CGPath];
[self.backScrollView.layer addSublayer:layer];
}
//获取两点之间控制点
- (CGPoint)getControlPointWithFirstPoint:(CGPoint)firstPoint
SecondPoint:(CGPoint)secondPoint{ CGPoint controlPoint = [self getMindPointWithFirstPoint:firstPoint secondPoint:secondPoint]; CGFloat diffY = fabs(secondPoint.y - controlPoint.y); if (firstPoint.y < secondPoint.y) controlPoint.y += diffY; else if (firstPoint.y > secondPoint.y) controlPoint.y -= diffY; return controlPoint;
}
//获取两点之间中心点
- (CGPoint)getMindPointWithFirstPoint:(CGPoint)firstPoint
secondPoint:(CGPoint)secondPoint{
return CGPointMake((firstPoint.x + secondPoint.x)/, (firstPoint.y + secondPoint.y)/);
}

效果图

3、绘制折线

- (void)drawView{
UIBezierPath *path = [UIBezierPath bezierPath];
DrawModel *firstModel = [self.dataArr firstObject];
CGPoint firstPoint = firstModel.currPoint;
[path moveToPoint:firstPoint];
if (self.dataArr.count<) {
return;
}
for (int i=; i<self.dataArr.count; i++) {
DrawModel *seconModel = self.dataArr[i];
CGPoint secondPoint = seconModel.currPoint;
[path addLineToPoint:secondPoint]; }
CAShapeLayer *layer = [CAShapeLayer layer];
layer.lineWidth = ;
layer.strokeColor = [UIColor redColor].CGColor;
layer.fillColor = [UIColor clearColor].CGColor;
layer.path = [path CGPath];
[self.backScrollView.layer addSublayer:layer];
}

效果图

iOS绘制线条的使用的更多相关文章

  1. iOS 动画绘制线条颜色渐变的折线图

    效果图 .................... 概述 现状 折线图的应用比较广泛,为了增强用户体验,很多应用中都嵌入了折线图.折线图可以更加直观的表示数据的变化.网络上有很多绘制折线图的demo,有 ...

  2. IOS绘制渐变背景色折线图的一种尝试

    1.绘制折线图 上次在群里看到一个折线图划的很漂亮,自己想实现一个这样的 ,但是一直没什么头绪,不知道怎么做,就开始在网上查找划线,绘 制渐变色这一块的内容,用最笨的方式,自己尝试的写了一些,也没 有 ...

  3. 使用html5 Canvas绘制线条(直线、折线等)

    使用html5 Canvas绘制直线所需的CanvasRenderingContext2D对象的主要属性和方法(有"()"者为方法)如下: 属性或方法 基本描述 strokeSty ...

  4. GDI基础(1):绘制线条和图形

    1. 绘制一个像素点:SetPixel(). 绘制直线:MoveTo(),LineTo(). 绘制多个首尾相连的线:Polyline(). 绘制矩形:FrameRect(),Rectangle(),F ...

  5. html5的canvas绘制线条,moveTo和lineTo详解

    今天在看html5,里面新增的属性有一个canvas,它相当于一个画布你可以用js在里面画你想要的效果!我在w3c的手册里面看到用moveTo和lineTo绘制线条讲的不是很清楚,尤其是moveTo和 ...

  6. canvas绘制线条详解

    canvas详解----绘制线条 <!DOCTYPE html> <html> <head> <title>canvas详解</title> ...

  7. IOS开发 图形绘制,绘制线条,矩形,和垂直和居中绘制文字

    概述 吐槽下IOS下 的图形绘图,代码冗长,不得不自己重新封装方法.整理形成本文. 绘制线 // 绘制直线 + (void)toDrawLineFromX:(CGFloat)x1 Y:(CGFloat ...

  8. iOS绘制坐标图,折线图-Swift

    坐标图,经常会在各种各样的App中使用,最常用的一种坐标图就是折线图,根据给定的点绘制出对应的坐标图是最基本的需求.由于本人的项目需要使用折线图,第一反应就是搜索已经存在的解决方案,因为这种需求应该很 ...

  9. 转:iOS绘制一个UIView

    绘制一个UIView 绘制一个UIVIew最灵活的方式就是由它自己完成绘制.实际上你不是绘制一个UIView,你只是子类化了UIView并赋予子类绘制自己的能力.当一个UIVIew需要执行绘图操作的时 ...

随机推荐

  1. [BOI2003]团伙

    题目描述 1920年的芝加哥,出现了一群强盗.如果两个强盗遇上了,那么他们要么是朋友,要么是敌人.而且有一点是肯定的,就是: 我朋友的朋友是我的朋友: 我敌人的敌人也是我的朋友. 两个强盗是同一团伙的 ...

  2. 【POJ】1251 Jungle Roads

    题目链接:http://poj.org/problem?id=1251 题意:n个村庄字母标号,每个字母后跟m个字母,表示该字母到mi的距离.求构建所有村庄道路的最短距离. 题解:最小生成树裸题.注意 ...

  3. Nginx+win10安装配置

    一.前言 Nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器,同时也提供了IMAP/POP3/SMTP服务.Nginx可以进行反向代理.负载均衡.HTTP服务器(动静分离).正向代 ...

  4. go 简介与包

    简介 Go语言是一种新的语言,一种并发的.带垃圾回收的.快速编译的语言.它具有以下特点: 1.它可以在一台计算机上用几秒钟的时间编译一个大型的Go程序. 2.Go语言为软件构造提供了一种模型,它使依赖 ...

  5. PKPM快捷键

    e删除sc删除节点hq绘制直线墙lbz布置梁zz楼层组装bsc板生成bxg板修改门窗洞dbz(洞布置)全房间洞(fd)正交轴网zww拉伸s

  6. java排序及泛型

    一.用泛型实现快排,可以传入不通类型进行排序,比如String数组,Integer数组. /** * 快速排序 * * @author chx * */ public class QuickSort ...

  7. PHP算法之增减字符串匹配

    给定只含 "I"(增大)或 "D"(减小)的字符串 S ,令 N = S.length. 返回 [0, 1, ..., N] 的任意排列 A 使得对于所有 i ...

  8. RAKsmart新出香港服务器的优势

    RAKsmart为了更好地服务用户,所以最近RAKsmart新推出得香港服务器又带给了用户更多的选择,那这次RAKsmart新推出香港服务器有哪些优势呢? 1.带宽更大可升至10Mpbs 香港服务器的 ...

  9. Windows cd

    显示当前目录名或改变当前目录. CHDIR [/D] [drive:][path]CHDIR [..]CD [/D] [drive:][path]CD [..] ..   指定要改成父目录. 键入 C ...

  10. poj2954Triangle

    传送门 Pick定理 定点坐标为整点的三角形,面积为S,边上的整点个数为L,三角形内部整点个数为N S=N+L/2-1 //Achen #include<algorithm> #inclu ...