ios 学习之你画我话绘图五 构造路径基础知识
来源:互联网 发布:微信程序源码 编辑:程序博客网 时间:2024/04/30 22:59
1 前言
构造和绘制路径,能够在图形环境上画任意形状.
2 代码实例
ZYViewControllerView.m
[plain] - (void)drawRect:(CGRect)rect{
//创建路径 创建一个新的 CGMutablePathRef 类型的可变路径并返回其句柄。
CGMutablePathRef path = CGPathCreateMutable();
/* How big is our screen? We want the X to cover the whole screen */
//范围为整个屏幕
CGRect screenBounds = [[UIScreen mainScreen] bounds];
//从左上角开始画路径 将路径上当前画笔位置移动到 CGPoint 类型的参数指定的点。
CGPathMoveToPoint(path, NULL,screenBounds.origin.x, screenBounds.origin.y);
//从左上角连线到右下角 从画笔当前位置向指定位置绘制一条线段。
CGPathAddLineToPoint(path,NULL, screenBounds.size.width, screenBounds.size.height);
//开始另一点从右上角
CGPathMoveToPoint(path,NULL, screenBounds.size.width, screenBounds.origin.y);
//从右上角到左下角
CGPathAddLineToPoint(path,NULL, screenBounds.origin.x, screenBounds.size.height);
//获得当前图形的上下文
CGContextRef currentContext = UIGraphicsGetCurrentContext();
/* Add the path to the context so we candraw it later */
//添加路径到路径上下文中 向图形环境上添加一个路径(由一个路径句柄指定),该路径已经准备好被绘制。
CGContextAddPath(currentContext,path);
//设置蓝色
[[UIColor blueColor] setStroke];
//画图 在图形环境上绘制指定路径
/*kCGPathStroke
画线来标记路径的边界或边缘,使用选中的绘图色。
kCGPathFill
用选中的填充色,填充被路径包围的区域。
kCGPathFillStroke
组合绘图和填充。用当前填充色填充路径,并用当前绘图色绘制路径边界。下面我们会看到一个使用此方 法的例子。
*/
CGContextDrawPath(currentContext, kCGPathStroke);
//释放路径
CGPathRelease(path);
}
- (void)drawRect:(CGRect)rect{
//创建路径 创建一个新的 CGMutablePathRef 类型的可变路径并返回其句柄。
CGMutablePathRef path = CGPathCreateMutable();
/* How big is our screen? We want the X to cover the whole screen */
//范围为整个屏幕
CGRect screenBounds = [[UIScreen mainScreen] bounds];
//从左上角开始画路径 将路径上当前画笔位置移动到 CGPoint 类型的参数指定的点。
CGPathMoveToPoint(path, NULL,screenBounds.origin.x, screenBounds.origin.y);
//从左上角连线到右下角 从画笔当前位置向指定位置绘制一条线段。
CGPathAddLineToPoint(path,NULL, screenBounds.size.width, screenBounds.size.height);
//开始另一点从右上角
CGPathMoveToPoint(path,NULL, screenBounds.size.width, screenBounds.origin.y);
//从右上角到左下角
CGPathAddLineToPoint(path,NULL, screenBounds.origin.x, screenBounds.size.height);
//获得当前图形的上下文
CGContextRef currentContext = UIGraphicsGetCurrentContext();
/* Add the path to the context so we candraw it later */
//添加路径到路径上下文中 向图形环境上添加一个路径(由一个路径句柄指定),该路径已经准备好被绘制。
CGContextAddPath(currentContext,path);
//设置蓝色
[[UIColor blueColor] setStroke];
//画图 在图形环境上绘制指定路径
/*kCGPathStroke
画线来标记路径的边界或边缘,使用选中的绘图色。
kCGPathFill
用选中的填充色,填充被路径包围的区域。
kCGPathFillStroke
组合绘图和填充。用当前填充色填充路径,并用当前绘图色绘制路径边界。下面我们会看到一个使用此方 法的例子。
*/
CGContextDrawPath(currentContext, kCGPathStroke);
//释放路径
CGPathRelease(path);
}
隐藏状态条
此例中,我要隐藏程序的状态条:请找到 Info.plist,并增加一个 UIStatusBarHidden 键,将其值设置为 YES
- ios 学习之你画我话绘图五 构造路径基础知识
- ios 学习之你画我话绘图七 椭圆形
- ios 学习之你画我话绘图三 画线
- ios 学习之你画我话绘图六 矩形
- ios 学习之你画我话绘图一 绘制文本和图像
- ios 学习之你画我话绘图二 熟悉下CGContextRef
- ios 学习之你画我话绘图四 读取pdf (官方代码)
- iOS 高级绘图之路径剪切
- IOS开发(81)之构造路径
- iOS开发学习之Quartz2D绘图
- iOS开发学习之Quartz2D绘图
- Ios高级绘图之路径剪切和蒙版
- Hello World感知机,懂你我心才安息 (深度学习入门系列之五)
- 我的java学习之路-基础知识
- ios 图形与动画学习笔记 构造路径(CGPathCreateMutable)
- IOS绘图学习笔记
- iOS转前端之HTML基础知识学习
- IOS之绘图
- Zookeeper工作原理2
- 八皇后问题
- 敏捷十年,成效几何?
- C# 序列化 与 反序列化
- java的集合框架
- ios 学习之你画我话绘图五 构造路径基础知识
- Zookeeper典型引用场景
- 打倒软件开发中的形式主义
- ResourceBundle的使用
- apache安全配置tips
- Wifi移植文档 - android2.2及android2.3版本
- Windows内核模式Playloads
- 图解数据结构(9)——左偏树
- java 局部变量和全局变量问题