iphone CGContextRef 使用画…
2013-08-19 18:20
274 查看
原文地址:iphone CGContextRef 使用画一些简单图形作者:若水一叶
获取上下文
CGContextRef context = UIGraphicsGetCurrentContext();
画一个正方形图形 没有边框
CGContextSetRGBFillColor(context, 0, 0.25, 0, 0.5);
CGContextFillRect(context, CGRectMake(2, 2, 270, 270));
CGContextStrokePath(context);
写文字
CGContextSetLineWidth(context, 1.0);
CGContextSetRGBFillColor (context, 1, 1, 1,
1.0);
UIFont *font = [UIFont
boldSystemFontOfSize:11.0];
[@"fangyp" drawInRect:CGRectMake(40, 40, 80, 20)
withFont:font];
画一条线
CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5,
0.5);//线条颜色
CGContextMoveToPoint(context, 20, 20);
CGContextAddLineToPoint(context, 200,20);
CGContextStrokePath(context);
画正方形边框
CGContextSetRGBStrokeColor(context, 1, 1.0, 1.0,
1.0);
CGContextSetLineWidth(context, 2.0);
CGContextAddRect(context, CGRectMake(2, 2, 270, 270));
CGContextStrokePath(context);
//////////////////转自:http://yangping-account.iteye.com/blog/1116960///////////////////////
从UIImageView中获取CGContextRef:
(从别人那转的,没用过)
UIGraphicsBeginImageContextWithOptions(newImageSize, YES,
0);
CGContextRef context = UIGraphicsGetCurrentContext();
// drawing commands go here
UIImage *newImage =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
获取上下文
CGContextRef context = UIGraphicsGetCurrentContext();
画一个正方形图形 没有边框
CGContextSetRGBFillColor(context, 0, 0.25, 0, 0.5);
CGContextFillRect(context, CGRectMake(2, 2, 270, 270));
CGContextStrokePath(context);
写文字
CGContextSetLineWidth(context, 1.0);
CGContextSetRGBFillColor (context, 1, 1, 1,
1.0);
UIFont *font = [UIFont
boldSystemFontOfSize:11.0];
[@"fangyp" drawInRect:CGRectMake(40, 40, 80, 20)
withFont:font];
画一条线
CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5,
0.5);//线条颜色
CGContextMoveToPoint(context, 20, 20);
CGContextAddLineToPoint(context, 200,20);
CGContextStrokePath(context);
画正方形边框
CGContextSetRGBStrokeColor(context, 1, 1.0, 1.0,
1.0);
CGContextSetLineWidth(context, 2.0);
CGContextAddRect(context, CGRectMake(2, 2, 270, 270));
CGContextStrokePath(context);
//////////////////转自:http://yangping-account.iteye.com/blog/1116960///////////////////////
从UIImageView中获取CGContextRef:
(从别人那转的,没用过)
UIGraphicsBeginImageContextWithOptions(newImageSize, YES,
0);
CGContextRef context = UIGraphicsGetCurrentContext();
// drawing commands go here
UIImage *newImage =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
相关文章推荐
- 新手必用 iPhone iBus详细使用教程
- iPhone必用 installer软件详细使用教程
- iPhone必用 新版installer详细使用教程
- 新版iPhone PC Suite完全详细使用教程
- 使用GPRS 让你的iPhone能上网能通话教程
- iPhone LumaQQ聊天软件详细使用教程
- Claw iPhone软件破解套件使用教程
- iPhone使用大全第二讲《Installer 3》
- UICollectionView 使用
- Media Scanner 扫码媒体文件的使用…
- vmware 使用技巧及报错解决方案
- 在使用MyEclipse 6中不能使用 alt …
- 知易Cocos2D-iPhone 游戏开…
- PLSQL Developer 64位系统如何使用
- 【转】QEventLoop 的使用两例
- find 命令的mtime参数的使用
- 如何在iOS 8中使用Swift和Xco…
- iPhone入门 - UIAlertView用法
- C 语言中 标识符的使用机制
- GPS设备参数 术语及使用方案整理收…