iPhone图形编程 简单代码
2012-09-11 16:01
162 查看
-(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应用程序编程指南-图形和描画
- java基于TCP的socket编程简单实现[代码实践过]
- [20180313智慧餐厅推荐系统02]基于python的socket编程代码,实现PC与服务器的简单通信
- 随想录(最简单的windows图形编程之Easyx)
- 宋体、代码-iOS网络编程实践--NSStream实现TCP Socket iPhone客户端-by小雨
- apue编程之参考df代码写的一个简单的df命令的源代码
- 简单图形编程的学习(2)---点 (small basic实现)
- iPhone的Socket编程使用开源代码之…
- iPhone 编程常用代码
- D3D编程之绘制简单图形
- iPhone开发之UIScrollView滚动组件的使用——纯代码实现图形的横向与纵向滚动
- iphone编程,使用代码结束自己的一些研究。
- 编程的智慧,如何编写简单优雅的代码
- 简单图形编程的学习(1)---文字 (Qt实现)
- 可视化编程 Tips 之"无需代码设置圆角" "简单处理让我们可以无需代码设置边框颜色"
- 简单图形编程的学习(1)---文字 (small basic实现)
- android网络编程之android连接网络的简单示例代码
- 回归游戏的世界,简单图形编程学习的开始
- Linux网络编程之socket简单通信TCP--服务端代码
- 常用IPHONE 编程 基础代码