UIBezierPath使用

贝塞尔曲线作用

贝塞尔曲线路径可用来绘制自定义路径,圆,弧度,矩形,单独圆角矩形等

UIBerzierPath类介绍

初始化方法

    /// MARK: - 初始化方法【常规路径】/// 矩形public convenience init(rect: CGRect)/// 椭圆 形状依赖于矩形(比如当矩形为正方形的时候为圆形)public convenience init(ovalIn rect: CGRect)/// 圆角矩形 四遍圆角一致public convenience init(roundedRect rect: CGRect, cornerRadius: CGFloat) // rounds all corners with the same horizontal and vertical radius/// 圆角矩形 可以设置任意一个或者多个圆角【corners控制】 cornerRadii: CGSize 圆角宽高参考【详情键cornerRadii参数说明】public convenience init(roundedRect rect: CGRect, byRoundingCorners corners: UIRectCorner, cornerRadii: CGSize)/// 弧度路径  radius: 圆半径  startAngle:弧度 比如二分之π(1(CGFloat.pi)/2)  clockwise: 是否顺手针public convenience init(arcCenter center: CGPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool)/// 根据CGPath初始化public convenience init(cgPath CGPath: CGPath)

矩形单独设置某个圆角(cornerRadii参数说明)

在进行单独某个圆角设置的时候,需要设置圆角参数,类型未CGSize , 说明圆角成度根据宽高共同决定,但是两个值得有效范围为0到两边中最小值得一半

效果图参考

路径绘制方法

    // MARK: -  自定义路径绘制【通过点与点之间的绘制】open func move(to point: CGPoint)     // 开始绘制点时open func addLine(to point: CGPoint)  // 点与点之间用线连接/// 三次方贝塞尔曲线open func addCurve(to endPoint: CGPoint, controlPoint1: CGPoint, controlPoint2: CGPoint)/// 二次贝塞尔曲线open func addQuadCurve(to endPoint: CGPoint, controlPoint: CGPoint)@available(iOS 4.0, *)open func addArc(withCenter center: CGPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool)open func close()open func removeAllPoints()/// 添加其他路径open func append(_ bezierPath: UIBezierPath)

其他属性和方法

open var cgPath: CGPath  // 对应的cgPath/// 逆转路径 【路径外表一致,只是最后一个点为最开始的点】@available(iOS 6.0, *)open func reversing() -> UIBezierPath// Transforming pathsopen func apply(_ transform: CGAffineTransform)// MARK: - 路径信息open var isEmpty: Bool { get }open var bounds: CGRect { get }  // 路径包含的矩形open var currentPoint: CGPoint { get }open func contains(_ point: CGPoint) -> Bool// MARK: - 绘制属性/// 线条颜色宽度open var lineWidth: CGFloat/// 线条起点和终点处理【值枚举 butt:默认  round:圆角  square:方形】open var lineCapStyle: CGLineCap/// 线条拐角处理【值枚举 miter:斜切(默认值)  round:圆角(圆滑)  bevel:斜角】open var lineJoinStyle: CGLineJoin/// 斜切限制  仅仅在 lineJoinStyle is kCGLineJoinMiter 有效open var miterLimit: CGFloat/// 曲线平坦经度 越小越光滑但是渲染越慢open var flatness: CGFloat  // 默认值0.6/// 是否使用奇偶绕线规则open var usesEvenOddFillRule: Bool // Default is NO. When YES, the even-odd fill rule is used for drawing, clipping, and hit testing./// 设置虚线open func setLineDash(_ pattern: UnsafePointer<CGFloat>?, count: Int, phase: CGFloat)open func getLineDash(_ pattern: UnsafeMutablePointer<CGFloat>?, count: UnsafeMutablePointer<Int>?, phase: UnsafeMutablePointer<CGFloat>?)// Path operations on the current graphics context/// 设置路径环境 比如设置颜色红色填充 UIColor.red.setFill()  之后path.fill()即可设置路径颜色open func fill()/// 设置填充环境 比如设置颜色蓝色填充 UIColor.blue.setStroke()  之后path.strocke()即可设置路径颜色open func stroke()// These methods do not affect the blend mode or alpha of the current graphics context/// 指定混合模式和透明度填充open func fill(with blendMode: CGBlendMode, alpha: CGFloat)/// 指定混合模式和透明度填充路径open func stroke(with blendMode: CGBlendMode, alpha: CGFloat)/// 与当前图形上下文的剪切路径相交于接收方路径所包围的区域,并使生成的形状为当前剪切路径[具体不太懂]open func addClip()

弧度图解

二次贝塞尔曲线图解

三次贝赛尔曲线图解

路径虚线

        let path = UIBezierPath(ovalIn: CGRect(x: 10, y: 40 , width: 100, height: 100))UIColor.red.setStroke()/// 虚线空白【是一个数组】var dashConfig: [CGFloat] = [3.0,4.0]//  注意参数形式使用的是地址  count 为虚线数组数量。 phase参数效果明白path.setLineDash(&dashConfig, count:dashConfig.count , phase: 0)path.stroke() // 这个一定要放在各种属性设置后面

具体用法实例见下一篇《自定义路径绘图实例》

UIBezierPath使用相关推荐

  1. iOS通过CAShapeLayer和UIBezierPath画环形进度条

    UIBezierPath可以绘制矢量路径,而CAShapeLayer是Layer的子类,可以在屏幕进行绘制,本文主要思想是:CAShapeLayer按照UIBezierPath的矢量路径进行绘制. 效 ...

  2. 使用 UIBezierPath 进行简单的图形绘制

    这篇文章介绍UIBezierPath的详细的使用, 以及一些细节! 创建一个XTBezierPath继承于UIView的类 使用drawRect 完成图形的绘制 在drawRect方法完成绘制 使用  ...

  3. UIBezierPath和CAShapeLayer创建不规则View(Swift 3.0)

    最近一个朋友在做图片处理的 App,想要实现类似 MOLDIV App 拼图的UI效果(如何创建不规则的 view),就问我有什么想法.我首先想到的就是 UIBezierPath+CAShapeLay ...

  4. UIBezierPath介绍

    前言 UIBezierPath是UIKit中的一个关于图形绘制的类,是通过Quartz 2D也就是CG(Core Graphics)CGPathRef的封装得到的,从高级特性支持来看不及CG. UIB ...

  5. UIBezierPath 的使用介绍

      使用UIBezierPath类可以创建基于矢量的路径.此类是Core Graphics框架关于path的一个封装.使用此类可以定义简单的形状,如椭圆或者矩形,或者有多个直线和曲线段组成的形状. 1 ...

  6. UIBezierPath路径绘图

    UIBezierPath路径绘图 一.新建一个playground 二.新建一个类继承与UIView 三.重写类中的drawRect()方法 四.定义坐标点(我们这里定义五个点,打算绘制一个五角星) ...

  7. UIBezierPath画圆弧的记录

    UIBezierPath通过 - (void)addArcWithCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)s ...

  8. UIBezierPath绘制虚线

    - (void) typeDashLine { // 1. 先创建三条路径, 有对比更有助于理解     UIBezierPath *path = [UIBezierPath bezierPath]; ...

  9. UIBezierPath的使用(持续更新)

    UIBezierPath的使用 1. 使用UIBezierPath绘制多边形 // 获取pathUIBezierPath *aPath = [UIBezierPath bezierPath];// 设 ...

最新文章

  1. Redis中哈希hash数据类型(增加修改(设置单一属性、设置多个属性)、获取(获取键所有属性、获取单一属性值、获取多个属性值)、删除、使用hash可能出现的问题)
  2. 深入探究Java中equals()和==的区别是什么
  3. DigSci科学数据挖掘大赛-亚军方案分享
  4. mysql一张表1亿天数据_1亿条数据在PHP中实现Mysql数据库分表100张
  5. Spring Boot多数据源配置与使用
  6. python tkinter text改变文本字体颜色_如何更改Tkinter中文本的颜色?
  7. java中abcd_java中请不要出现aBcd类似的变量名
  8. Google猜画小歌升级:现在可以跟好友对战了
  9. gnuTLS 提供的 DTLS-API
  10. 图片完整检查linux,Linux 下的免费图片查看器
  11. GB/T14710|聊一聊医用电气设备的环境试验
  12. centos 查看版本号方法
  13. Java面试官最爱问的volatile关键字
  14. 5000字 大数据时代读书笔记_《大数据时代》读后感 读书笔记
  15. 蓝天热键驱动_创建快捷方式或热键以立即弹出特定的USB驱动器
  16. 关于股票的一些学习书籍
  17. Ubuntu 16.04 桌面字体太小让它大大大
  18. 【搞定算法】蓄水池算法
  19. Keil5.15使用GCC编译器编译STM32工程
  20. 向中级程序员转变必备的10个秘诀

热门文章

  1. 多线程学习-基础(十三)(学习参考·网摘) ArrayBlockingQueue源代碼解析(base jdk 1.8)...
  2. FineUIMvc随笔(6)对比WebForms和MVC中表格的数据库分页
  3. fastDFS同步问题讨论
  4. Oracle误删除数据和表的恢复办法包括truncate
  5. ==和equals()的区别
  6. 【阿里巴巴】CBU技术部招聘
  7. [转]MFC下关于“建立空文档失败”问题的分析
  8. AsyncTask工作机制简介
  9. Error:Execution failed for task ':myapp:dexDebug'. com.android.ide.common.process.ProcessExcepti
  10. win8 app内存溢出检测工具PerfView.exe的使用