iPhone图形编程 简单代码
来源:互联网 发布:印度朗洞事件 知乎 编辑:程序博客网 时间:2024/06/06 14:18
-(void)drawInContext:(CGContextRef)context
{
// Drawing with a white stroke color
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
// And drawing with a blue fill color
// 这是为了下面的填充方法准备的,填充方法会自动来找这个填充的颜色
CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0);
// Draw them with a 2.0 stroke width so they are a bit more visible.
CGContextSetLineWidth(context, 2.0);
// Add Rect to the current path, then stroke it
CGContextAddRect(context, CGRectMake(30.0, 30.0, 60.0, 60.0));
// 记住fill是对某个区域进行填充,stroke是对你指定的路径的一个描绘
//CGContextFillRect(context, CGRectMake(30.0, 30.0, 60.0, 60.0));
CGContextStrokePath(context);
// Stroke Rect convenience that is equivalent to above
// 跟上面等价,就不用在写CGContextStrokePath(context);这句话了,直接出图
CGContextStrokeRect(context, CGRectMake(30.0, 120.0, 60.0, 60.0));
// Stroke rect convenience equivalent to the above, plus a call to CGContextSetLineWidth().
CGContextStrokeRectWithWidth(context, CGRectMake(30.0, 210.0, 60.0, 60.0), 10.0);
// Demonstate the stroke is on both sides of the path.
// 保存当前图形的上下文,根据这个例子,我总结一下,当我在某些情况发生时,我只想改变某个部分的颜色,或则时大小子类的
// 这时候为了不影响后面的图形创建。例如下面的rects数组里面的三个矩形框,我不想让这个也跟着变化,所以我把即将改变的图形
// 上下文先给保存起来,这样在保存之后无论做什么样的改变,只要我在这个改变完成后在恢复回来,就不会影响我下面的图形状态
// 说白了图形上下文,我比做一张纸,我在这张纸的某个地方画了红色的图,然后我又在其他地方画了一个蓝色的图。蓝色图的配置参数
// 还是我之前的哪些设置,不会变
CGContextSaveGState(context);
CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
CGContextStrokeRectWithWidth(context, CGRectMake(30.0, 210.0, 60.0, 60.0), 2.0);
CGContextRestoreGState(context);
CGRect rects[] =
{
CGRectMake(120.0, 30.0, 60.0, 60.0),
CGRectMake(120.0, 120.0, 60.0, 60.0),
CGRectMake(120.0, 210.0, 60.0, 60.0),
};
// Bulk call to add rects to the current path.
CGContextAddRects(context, rects, sizeof(rects)/sizeof(rects[0]));
CGContextStrokePath(context);
// Create filled rectangles via two different paths.
// 创建填充矩形,用两个不同的路径
// Add/Fill path
CGContextAddRect(context, CGRectMake(210.0, 30.0, 60.0, 60.0));
CGContextFillPath(context);
// Fill convienience. (便利方法,对比下就知道)
CGContextFillRect(context, CGRectMake(210.0, 120.0, 60.0, 60.0));
}
- iPhone图形编程 简单代码
- 简单图形编程学习
- iphone CGContextRef 使用画一些简单图形
- iPhone应用程序编程指南-图形和描画
- iPhone应用程序编程指南---图形和描画
- iPhone应用程序编程指南(图形和描画)
- 常用IPHONE 编程 基础代码
- 常用IPHONE 编程 基础代码
- 常用IPHONE 编程 基础代码
- 简单的图形验证码识别代码
- 用代码绘制简单的图形
- 简单图形验证码生成 代码解析
- 代码:双重for循环打印简单图形
- D3D编程之绘制简单图形
- 简单图形编程学习(2)
- Python最简单的图形编程
- 【Python学习】之 简单图形编程
- Python最简单的图形编程
- flex super
- android 4.0.1源码编译,学习错误解决
- linux上如何搭建Vsftpd
- pig tutorial编译问题
- 系统调优思路
- iPhone图形编程 简单代码
- 2. Exercises and Problems——Introduction to Algorithms Third Edition
- 细讲解cocos2dx(v2.x)与(v1.x)的一些常用函数
- 职场感悟—刚入行,想晋升吗?
- js获得网页中某元素的坐标位置
- 路上看水
- 黑马程序员_JavaSE基础12 之 导入包 多线程的创建
- ZOJ1074
- leeboy的linux学习十三环境变量实例