您的位置:首页 > 其它

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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: