CGContext画线
来源:互联网 发布:mysql trigger 编辑:程序博客网 时间:2024/06/07 19:30
1 前言
得到图形环境,然后用 CGContextMoveToPoint 和 CGContextAddLineToPoint 函数来画线。
2 代码实例
ZYViewControllerView.m
[plain]
- (void)drawRect:(CGRect)rect{
[self drawRooftopAtTopPointof:CGPointMake(160.0f, 40.0f) textToDisplay:@"Miter"
lineJoin:kCGLineJoinMiter];
[self drawRooftopAtTopPointof:CGPointMake(160.0f, 180.0f) textToDisplay:@"Bevel"
lineJoin:kCGLineJoinBevel];
[self drawRooftopAtTopPointof:CGPointMake(160.0f, 320.0f) textToDisplay:@"Round"
lineJoin:kCGLineJoinRound];
}
/*
paramTopPoint:一个点,顶部在这一点
textToDisplay:内显示的文字
lineJoin:要使用的接合类型
kCGLineJoinMiter
接合点为尖角。这是默认的接合类型。
kCGLineJoinBevel
接合点为斜角
kCGLineJoinRound
接合点为圆角
*/
- (void) drawRooftopAtTopPointof:(CGPoint)paramTopPoint textToDisplay:(NSString *)paramText
lineJoin:(CGLineJoin)paramLineJoin{
/*设置线条颜色*/
[[UIColor brownColor] set];
//获得当前图形上下文
CGContextRef currentContext = UIGraphicsGetCurrentContext();
//设置连接类型
CGContextSetLineJoin(currentContext, paramLineJoin);
//设置线条宽度
CGContextSetLineWidth(currentContext,20.0f);
//设置开始点位置
CGContextMoveToPoint(currentContext,paramTopPoint.x - 140, paramTopPoint.y + 100);
//设置终点
CGContextAddLineToPoint(currentContext,paramTopPoint.x, paramTopPoint.y);
//设置另一个终点
CGContextAddLineToPoint(currentContext,paramTopPoint.x + 140, paramTopPoint.y + 100);
//画线
CGContextStrokePath(currentContext);
[[UIColor blackColor] set];
/* 写文字 */
CGPoint drawingPoint = CGPointMake(paramTopPoint.x - 40.0f,
paramTopPoint.y + 60.0f);
[paramText drawAtPoint:drawingPoint withFont:[UIFont boldSystemFontOfSize:30.0f]];
}
- CGContext画线
- CGContext 画线
- IOS的画线方法 CGContext
- CGContext
- CGContext
- CGContext
- CGContext
- CGContext
- 画线
- 画线
- 画线
- 画线
- 画线
- 画线
- 画线
- CGContext小记
- CGContext小记
- CGContext小记
- 自考的结束预示着新的开始
- 保存Google、Bing翻译的语音
- ASP.NET 下载的几种方法
- 高斯判别分析和朴素贝叶斯分类器
- MFC文档视图(二):标准消息
- CGContext画线
- 嵌入式 hi3518c平台SIMCOM5360E型号3G模块移植使用PPPD拨号(待续)
- 关于让iframe背景透明的方法
- 在RowCommand事件中获取索引值
- OV7620的使用
- BT656
- cmake+vs2008+opencv学习
- linux 资料收集
- [ACM] hdu 1085 Holding Bin-Laden Captive! (母函数变形)