【深入浅出IOS开发】IOS绘图基础
2014-12-20 08:01
239 查看
1.绘图的常用步骤
①获得设备上下文
CGContextRef ctr =
UIGraphicsGetCurrentContext();
②在设备上下文绘图
CGContextMoveToPoint(ctr,
10, 10);
CGContextAddLineToPoint(ctr,
50, 50);
③渲染到相应的View
CGContextFillPath(ctr);
一般来说绘制图形,通常是CGContextAdd*****,而更改某些属性则是CGContextSet*****.
绘制圆弧的时候,通常使用:
CGContextAddArc(ctr, 100, 100, 50, -M_PI_2, M_PI_4, 0);
其中参数的设置是以x轴为0,下面为+,上面为-。
①获得设备上下文
CGContextRef ctr =
UIGraphicsGetCurrentContext();
②在设备上下文绘图
CGContextMoveToPoint(ctr,
10, 10);
CGContextAddLineToPoint(ctr,
50, 50);
③渲染到相应的View
CGContextFillPath(ctr);
一般来说绘制图形,通常是CGContextAdd*****,而更改某些属性则是CGContextSet*****.
绘制圆弧的时候,通常使用:
CGContextAddArc(ctr, 100, 100, 50, -M_PI_2, M_PI_4, 0);
其中参数的设置是以x轴为0,下面为+,上面为-。
// Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code //draw3Tri(); //draw4Rect(); drawEcplise(); } void drawEcplise() { CGContextRef ctr = UIGraphicsGetCurrentContext(); // CGContextAddEllipseInRect(ctr, CGRectMake(20, 20, 100,200)); // CGContextAddArcToPoint(ctr, 10, 10, 50, 100, 100); //CGContextAddArc(ctr, 100, 100, 50, -M_PI_2, M_PI_4, 0); CGContextMoveToPoint(ctr, 50, 50); CGContextAddLineToPoint(ctr, 100, 100); CGContextSetRGBStrokeColor(ctr, 1, 0, 0, 1); CGContextSetLineWidth(ctr, 5); CGContextStrokePath(ctr); CGContextMoveToPoint(ctr, 150, 150); CGContextAddLineToPoint(ctr, 200, 200); CGContextSetRGBStrokeColor(ctr, 0, 0, 1, 1); CGContextSetLineWidth(ctr, 2); CGContextStrokePath(ctr); } void draw4Rect() { CGContextRef ctr = UIGraphicsGetCurrentContext(); CGContextAddRect(ctr, CGRectMake(10, 10, 80, 80)); CGContextFillPath(ctr); } void draw3Tri() { //1.获得设备上下文 CGContextRef ctr = UIGraphicsGetCurrentContext(); //2.在设备中绘图 CGContextMoveToPoint(ctr, 10, 10); CGContextAddLineToPoint(ctr, 50, 50); CGContextAddLineToPoint(ctr, 100, 0); CGContextAddLineToPoint(ctr, 10, 10); //3.渲染到view中 //CGContextStrokePath(ctr); CGContextFillPath(ctr); }
相关文章推荐
- 【深入浅出IOS开发】IOS绘图基础
- 【深入浅出IOS开发】IOS绘图基础
- 课程分享Objective-C深入浅出,ios开发零基础入门(Xcode入门及语法入门)
- Objective-C深入浅出,ios开发零基础入门(Xcode入门及语法入门)课程分享
- iOS开发之quartz 2d绘图基础
- 【IOS 开发学习总结-OC-64】Quartz 2D绘图(4-1)——Quartz 2D绘图基础+点线模式
- 【iOS-Cocos2d游戏开发之二十】精灵的基础知识点总汇(位图操作/贴图更换/重排z轴等)及制作简单遮盖层!
- IOS开发基础之──NSLog 输出格式详解
- IOS开发开篇之Objective-C语法基础
- IOS开发基础知识要点
- IOS开发笔记(五)---基础控件的使用(Text Filed ,Image View,Slider等)
- IOS开发基础之──MVC模式
- IOS开发基础之──viewDidUnload/dealloc调用分析
- Android UI开发专题(二) 之绘图基础
- ios开发kvo模式基础-Key-Value Observing 快速入门
- IOS开发基础之—MD5加密算法
- Android UI开发专题(二) 之绘图基础
- iOS开发笔记 3、iOS基础
- Android UI开发专题(二) 之绘图基础
- IOS开发基础之──单例模式