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); |
} |
UIBezierPath 的使用介绍的更多相关文章
- 贝塞尔曲线(UIBezierPath)属性、方法汇总
UIBezierPath主要用来绘制矢量图形,它是基于Core Graphics对CGPathRef数据类型和path绘图属性的一个封装,所以是需要图形上下文的(CGContextRef),所以一般U ...
- UIBezierPath用法
前言 笔者在写本篇文章之前,也没有系统学习过贝塞尔曲线,只是曾经某一次的需求需要使用到,才临时百度看了一看而且使用最基本的功能.现在总算有时间停下来好好研究研究这个神奇而伟大的贝塞尔先生! 笔者在学习 ...
- 【转】UIBezierPath精讲
http://www.henishuo.com/uibezierpath-draw/ 基础知识 使用UIBezierPath可以创建基于矢量的路径,此类是Core Graphics框架关于路径的封装. ...
- UIBezierPath精讲
前言 笔者在写本篇文章之前,也没有系统学习过贝塞尔曲线,只是曾经某一次的需求需要使用到,才临时百度看了一看而且使用最基本的功能.现在总算有时间停下来好好研究研究这个神奇而伟大的贝塞尔先生! 笔者在学习 ...
- 利用UIBezierPath实现一个带圆角的视图
- (void)drawRect:(CGRect)rect { // draw a box with rounded corners to fill the view - UIBezierPath * ...
- UIBezierPath
UIBezierPath 笔者在写本篇文章之前,也没有系统学习过贝塞尔曲线,只是曾经某一次的需求需要使用到,才临时百度看了一看而且使用最基本的功能.现在总算有时间停下来好好研究研究这个神奇而伟大的贝塞 ...
- 快速上手UIBezierPath
UIBezierPath主要用来绘制矢量图形,它是基于Core Graphics对CGPathRef数据类型和path绘图属性的一个封装,所以是需要图形上下文的(CGContextRef),所以一般U ...
- 利用贝塞尔曲线绘制(UIBezierPath)自定义iOS动态速度表,可以自定义刻度,刻度值,进度条样式
GitHub的Demo下载地址 使用UIBezierPath画图步骤: 创建一个UIBezierPath对象 调用-moveToPoint:设置初始线段的起点 添加线或者曲线去定义一个或者多个子路径 ...
- iOS UIBezierPath类 介绍
使用UIBezierPath类可以创建基于矢量的路径,这个类在UIKit中.此类是Core Graphics框架关于path的一个封装.使用此类可以定义简单的形状,如椭圆或者矩形,或者有多个直线和 ...
随机推荐
- iOS iOS7 20px 处理
- (void)viewWillAppear:(BOOL)animated { // View defaults to full size. If you want to customize the ...
- centos custom iso
http://www.smorgasbork.com/2012/01/04/building-a-custom-centos-6-kickstart-disc-part-1/ Create a dir ...
- mount挂载
与ln -s 功能类似 # mount --bind /data/public /home/user/public /etc/fstab # <file system> <mount ...
- ASP.NET的SEO:正则表达式
目前国内主流的网站内容管理系统中,有大部分是可以将动态的PHP.ASP.ASPX等文档直接生成HTML的.但是由于有些网站的内容较多,因此如果单纯的采取直接生成的方式,将会占用大量的服务器资源.在这种 ...
- WP8_访问ListBox中的Item项中的某个元素
How to access a Control placed inside ListBox ItemTemplate in WP7(转) In this post I am going to talk ...
- leetcode 27
27. Remove Element Given an array and a value, remove all instances of that value in place and retur ...
- poj3122 pie
方法:二分. 题目意思:要过生日了,我请大家吃pie,然后人数一共是f+1(我自己).每个人的pie不能是拼接的,而且每个人的面积是一样的,这样就用二分枚举. 范围是0-最大的那块pie. 然后用每一 ...
- 嵌入式linux移植LAMP服务器
一.工具准备工作 要想在ARM平台上移植一套Apache+Msql+PHP的Web型服务器. 所用物理机系统: Ubuntu 14.04 LTS(64位) 交叉编译环境: arm-linux-g ...
- vim与shell的切换
方法1: vim->shell: ctrl-z (挂起vim进程,相当于图形界面中的最小化) shell->vim: fg (foreground) 方法2: vim->shel ...
- POJ C++程序设计 编程题#1 编程作业—继承与派生
编程题#1 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 写一个MyStr ...