iOS绘制线条的使用
1、相关简介
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绘制线条的使用的更多相关文章
- iOS 动画绘制线条颜色渐变的折线图
效果图 .................... 概述 现状 折线图的应用比较广泛,为了增强用户体验,很多应用中都嵌入了折线图.折线图可以更加直观的表示数据的变化.网络上有很多绘制折线图的demo,有 ...
- IOS绘制渐变背景色折线图的一种尝试
1.绘制折线图 上次在群里看到一个折线图划的很漂亮,自己想实现一个这样的 ,但是一直没什么头绪,不知道怎么做,就开始在网上查找划线,绘 制渐变色这一块的内容,用最笨的方式,自己尝试的写了一些,也没 有 ...
- 使用html5 Canvas绘制线条(直线、折线等)
使用html5 Canvas绘制直线所需的CanvasRenderingContext2D对象的主要属性和方法(有"()"者为方法)如下: 属性或方法 基本描述 strokeSty ...
- GDI基础(1):绘制线条和图形
1. 绘制一个像素点:SetPixel(). 绘制直线:MoveTo(),LineTo(). 绘制多个首尾相连的线:Polyline(). 绘制矩形:FrameRect(),Rectangle(),F ...
- html5的canvas绘制线条,moveTo和lineTo详解
今天在看html5,里面新增的属性有一个canvas,它相当于一个画布你可以用js在里面画你想要的效果!我在w3c的手册里面看到用moveTo和lineTo绘制线条讲的不是很清楚,尤其是moveTo和 ...
- canvas绘制线条详解
canvas详解----绘制线条 <!DOCTYPE html> <html> <head> <title>canvas详解</title> ...
- IOS开发 图形绘制,绘制线条,矩形,和垂直和居中绘制文字
概述 吐槽下IOS下 的图形绘图,代码冗长,不得不自己重新封装方法.整理形成本文. 绘制线 // 绘制直线 + (void)toDrawLineFromX:(CGFloat)x1 Y:(CGFloat ...
- iOS绘制坐标图,折线图-Swift
坐标图,经常会在各种各样的App中使用,最常用的一种坐标图就是折线图,根据给定的点绘制出对应的坐标图是最基本的需求.由于本人的项目需要使用折线图,第一反应就是搜索已经存在的解决方案,因为这种需求应该很 ...
- 转:iOS绘制一个UIView
绘制一个UIView 绘制一个UIVIew最灵活的方式就是由它自己完成绘制.实际上你不是绘制一个UIView,你只是子类化了UIView并赋予子类绘制自己的能力.当一个UIVIew需要执行绘图操作的时 ...
随机推荐
- 深夜Python - 第1夜 - for 迷 in 迷思
深夜Python - 第1夜 - for 迷 in 迷思 在一个月黑风高的夜晚,我悄悄打开编辑器,进入程序的世界.刚刚学会Python的我,由于一段时间的过度装B,被委托优化一段程序,我信心十足地接下 ...
- python中面向对象
一.Python经典类与新类 经典类:如果没有直接或间接的子类化一个对象,也就是说如果没有指定一个父类,或者是如果子类化的基本类没有父类,那么就定义了经典类: class classics: 'def ...
- arm-linux-gcc 的使用
1. 编译 C 文件,生成 elf 可执行文件 h1.c 源文件 #include <stdio.h> void hellofirst(void) { printf("The f ...
- 随笔记录 Linux基本操作命令 2019.7.27
临时关闭防火墙systemctl stop firewalld永久关闭防火墙systemctl disable firewalld 临时关闭selinux安全机制setenforce 0永久关闭sel ...
- log-slave-updates参数
从库做为其他从库的主库时 log-slave-updates参数是必须要添加的,因为从库要作为其他从库的主库,必须添加该参数.该参数就是为了让从库从主库复制数据时可以写入到binlog日志,为什么要用 ...
- centos 下载并安装nodejs
安装方法1——直接部署 1.首先安装wget ,这个一般都有自带有的,可能已经在系统里安装好了的. yum install -y wget 如果已经安装了可以跳过该步 2.下载nodejs最新的tar ...
- Windows ping
用法: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS] [-r count] [-s count] [[-j ...
- DDOS 单例
DDOS.H #pragma once //g++ ../../../Main.cpp ../../../DDOS.cpp -lpthread #include <stdio.h> #in ...
- The Preliminary Contest for ICPC Asia Nanjing 2019 C. Tsy's number 5
https://nanti.jisuanke.com/t/41300 题意:求\(\sum_{i=1}^n\phi(i)\phi(j)2^{\phi(i)\phi(j)}\) \(f_i=\sum_{ ...
- SP1296 SUMFOUR - 4 values whose sum is 0
传送门 解题思路 四个数组一起做有点炸.先把他们合并成两个数组,然后让一个数组有序,枚举另一个数组的元素,二分即可.时间复杂度\(O(n^2logn^2)\) 代码 #include<iostr ...