UIBezierPath 的使用介绍
UIBezierPath* aPath = [UIBezierPath bezierPath]; |
// Set the starting point of the shape. |
[aPath moveToPoint:CGPointMake(100.0, 0.0)]; |
// Draw the lines |
[aPath addLineToPoint:CGPointMake(200.0, 40.0)]; |
[aPath addLineToPoint:CGPointMake(160, 140)]; |
[aPath addLineToPoint:CGPointMake(40.0, 140)]; |
[aPath addLineToPoint:CGPointMake(0.0, 40.0)]; |
[aPath closePath]; |
bezierPathWithArcCenter:radius:startAngle:endAngle:clockwise:
的参数定义了我们想要的arc的圆,以及arc的起点和终点。
Creating a new arc path
// pi is approximately equal to 3.14159265359 |
#define DEGREES_TO_RADIANS(degrees) ((pi * degrees)/ 180) |
- (UIBezierPath*)createArcPath |
{ |
UIBezierPath* aPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) |
radius:75 |
startAngle:0 |
endAngle:DEGREES_TO_RADIANS(135) |
clockwise:YES]; |
return aPath; |
} |
Cubic curve:
addCurveToPoint:controlPoint1:controlPoint2:
Quadratic curve:
addQuadCurveToPoint:controlPoint:
bezierPathWithRect:
and bezierPathWithOvalInRect:
方法去创建椭圆或者矩形形状的path。这两个方法都创建了一个新的path对象,并用指定的形状去初始化它们。我们可以使用返回的path对象或者根据需要去添加更多的形状。
CGPathAddEllipseInRect
方法非常的简单使用,也更准确。
// Create the path data |
CGMutablePathRef cgPath = CGPathCreateMutable(); |
CGPathAddEllipseInRect(cgPath, NULL, CGRectMake(0, 0, 300, 300)); |
CGPathAddEllipseInRect(cgPath, NULL, CGRectMake(50, 50, 200, 200)); |
// Now create the UIBezierPath object |
UIBezierPath* aPath = [UIBezierPath bezierPath]; |
aPath.CGPath = cgPath; |
aPath.usesEvenOddFillRule = YES; |
// After assigning it to the UIBezierPath object, you can release |
// your CGPathRef data type safely. |
CGPathRelease(cgPath); |
Mixing Core Graphics and UIBezierPath
calls
UIBezierPath* aPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 300, 300)]; |
// Get the CGPathRef and create a mutable version. |
CGPathRef cgPath = aPath.CGPath; |
CGMutablePathRef mutablePath = CGPathCreateMutableCopy(cgPath); |
// Modify the path and assign it back to the UIBezierPath object |
CGPathAddEllipseInRect(mutablePath, NULL, CGRectMake(50, 50, 200, 200)); |
aPath.CGPath = mutablePath; |
// Release both the mutable copy of the path. |
CGPathRelease(mutablePath); |
Drawing a path in a view
- (void)drawRect:(CGRect)rect |
{ |
// Create an oval shape to draw. |
UIBezierPath* aPath = [UIBezierPath bezierPathWithOvalInRect: |
CGRectMake(0, 0, 200, 100)]; |
// Set the render colors |
[[UIColor blackColor] setStroke]; |
[[UIColor redColor] setFill]; |
CGContextRef aRef = UIGraphicsGetCurrentContext(); |
// If you have content to draw after the shape, |
// save the current state before changing the transform |
//CGContextSaveGState(aRef); |
// Adjust the view's origin temporarily. The oval is |
// now drawn relative to the new origin point. |
CGContextTranslateCTM(aRef, 50, 50); |
// Adjust the drawing options as needed. |
aPath.lineWidth = 5; |
// Fill the path before stroking it so that the fill |
// color does not obscure the stroked line. |
[aPath fill]; |
[aPath stroke]; |
// Restore the graphics state before drawing any other content. |
//CGContextRestoreGState(aRef); |
} |
转载于:https://www.cnblogs.com/496668219long/p/4449332.html
UIBezierPath 的使用介绍相关推荐
- ios 贝塞尔曲线 颜色填充_IOS 贝塞尔曲线(UIBezierPath)属性、方法整理
IOS 贝塞尔曲线详解 开发IOS的朋友都知道IOS 贝塞尔曲线的重要性,由于经常会用到这样的东西,索性抽时间就把相应所有的属性,方法做一个总结. UIBezierPath主要用来绘制矢量图形,它是基 ...
- iOS quartzCore学习之UIBezierPath 详解
转自: http://blog.csdn.net/hdfqq188816190/article/details/51435219 UIBezierPath主要用来绘制矢量图形,它是基于Core Gra ...
- UIBezierPath
学习UIBezierPath画图 笔者在写本篇文章之前,也没有系统学习过贝塞尔曲线,只是曾经某一次的需求需要使用到,才临时百度看了一看而且使用最基本的功能.现在总算有时间停下来好好研究研究这个神奇而伟 ...
- iOS: UIBezierPath简介及静态图形实现
UIBezierPath介绍 基本介绍: UIBezierPath可以用来创建矢量的路径和图形,使用此类可以定义各种图形.我们用直线和弧形的组合来创建复杂的图形.每一个直线段或者曲线段的结束的地方是下 ...
- cic曲线是什么_贝塞尔曲线基本用法
使用UIBezierPath可以创建基于矢量的路径,此类是Core Graphics框架关于路径的封装.使用此类可以定义简单的形状,如椭圆.矩形或者有多个直线和曲线段组成的形状等. UIBezierP ...
- iOS -- 学习资料总结(转载)
先著名转载地址:https://www.jianshu.com/p/c47c24ab1e76/ 关于iOS学习进阶的必读一些博客总结 经过一周的思考还是决定重组一下优秀的博客,首次整理这些博客比较乱, ...
- 关于iOS学习进阶的必读一些博客总结
关于iOS学习进阶的必读一些博客总结 作者 Raybon_lee 2016.01.16 22:28* 字数 3110 经过一周的思考还是决定重组一下优秀的博客,首次整理这些博客比较乱,但是后期会慢慢增 ...
- UIBezierPath介绍
前言 UIBezierPath是UIKit中的一个关于图形绘制的类,是通过Quartz 2D也就是CG(Core Graphics)CGPathRef的封装得到的,从高级特性支持来看不及CG. UIB ...
- 使用 UIBezierPath 进行简单的图形绘制
这篇文章介绍UIBezierPath的详细的使用, 以及一些细节! 创建一个XTBezierPath继承于UIView的类 使用drawRect 完成图形的绘制 在drawRect方法完成绘制 使用 ...
最新文章
- JSON在PHP中的基本应用
- jar包不用java命令_使不能运行的JAR文件可以使用java -jar运行
- springboot中配置mybatis数据源,使用阿里的 Druid 数据库连接池
- LeetCode872. Leaf-Similar Trees
- flowable实战(十五)关于流程设计器 bpmn.js与vue的整合
- 物流行业解决方案:聚焦物流行业数据痛点,帮助企业搭建数据平台
- 如何把一个整数转化成数组_「leetcode891」给定一个整数数组 A,考虑 A 的所有非空子序列...
- (转)windows 下 Java 及 Python 环境变量设置
- 阶段1 语言基础+高级_1-3-Java语言高级_08-JDK8新特性_第1节 常用函数接口_15_常用的函数式接口_Predicate接口练习-集合信息的筛选...
- 关于百度地图海量打点的问题
- 龙芯2f平台下 Debain 6编译Lighttpd并支持C语言cgi脚本编程
- Hans Petter Langtangen
- 网页图片上传到服务器
- Channel 接口EventLoop 接口 ChannelFuture 接口
- 落地零售智能体,百联集团全力打造面向未来的数字化商业体
- win10 操作中心是灰色无法选择 终极解决方法
- java八进制转换器,Java将八进制转换为十进制
- qnx学习笔记-QNX系统下载graphic镜像
- 关于 GNSS 系统的信号频点频率 + 可用卫星
- java里面用的什么字符集,以及汉字在其中占用的字节数