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. Spring REST(4)

    REST风格 /user/1    get请求  获取用户 /user/1 post请求   新增用户 /user/1 put请求     更新用户 /user/1 delete请求 删除用户 在Sp ...

  2. centos6.5离线安装pandas

    由于笔记本跑不动很多大赛的数据,遂转至申请的虚拟机(centos6.5)中,奈何学校的虚拟机没网,就开始了离线安装pandas的道路,当中有踩了好些坑,于是便产生了这篇文章~ 首先,自带的python ...

  3. 常用指令linux总结

    linux的基础操作命令: 常见命令: man 查看帮助文档 用法:man + 命令 help 查看指定命令的用法 用法: 命令 --help(有空格) tab linux下命令与文件名补全 用法:在 ...

  4. C# 创建DataTable并添加行和列

    DataTable dt=new DataTable dt.Columns.Add("numview", typeof(Int32)); dt.Columns.Add(" ...

  5. Android studio 添加引用Module项目 与 设置Module项目的Libs的Jar在主项目里使用

    前言 添加引用Module项目 设置Module项目的Libs的Jar在主项目里使用 1.在项目里添加libs包,并且加入jar 2.设置这个module项目的build.gradle depende ...

  6. Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0

    android studio  3.0 出现此问题可能是因为 你的android studio 时脱机状态 无法下载资源 这时候你可以点击左上角分File->Other Settings-> ...

  7. Maven - 深入理解maven构建生命周期和各种plugin插件

    作者:亚当-adam 来源:CSDN 原文:https://blog.csdn.net/zhaojianting/article/details/80321488 版权声明:本文为博主原创文章,转载请 ...

  8. 数据库实例性能调优利器:Performance Insights

    Performance Insights是什么 阿里云RDS Performance Insights是RDS CloudDBA产品一项专注于用户数据库实例性能调优.负载监控和关联分析的利器,以简单直 ...

  9. 基于vue的环信基本实时通信功能

    本篇文章借鉴了一些资料,然后在这个基础上,我将环信的实现全部都集成在一个组件里面进行实现: https://blog.csdn.net/github_35631540/article/details/ ...

  10. 0924CSP-S模拟测试赛后总结

    50分-rank28 我是第二机房垫底大垃圾. 赛时T1和T2其实想到了正解??安慰自己罢了. 真正的CSP-S的赛后你还能和主办方争论说自己其实想到了正解要求人家硬给你个省一不成?? 出题人不知道到 ...