iOS 用CGContextRef画虚线
来源:互联网 发布:中国废除汉字知乎 编辑:程序博客网 时间:2024/05/17 21:51
-画虚线需要用到函数:
CGContextSetLineDash
此函数需要四个参数:
- context
- phase
- lengths – 指明虚线是如何交替绘制
- count – lengths数组的长度
-(void)drawRect:(CGRect)rect{
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
CGFloat lengths[] = {10,10};
CGContextSetLineDash(context, 0, lengths,2);
CGContextMoveToPoint(context, 10.0, 20.0);
CGContextAddLineToPoint(context, 310.0,20.0);
CGContextStrokePath(context);
CGContextClosePath(context);
//CGFloat lengths[] = {10,5};
CGContextSetLineDash(context, 0, lengths, 2);
CGContextMoveToPoint(context, 0.0, 20.0);
CGContextAddLineToPoint(context, 310.0, 20.0);
CGContextStrokePath(context);
CGContextSetLineDash(context, 5, lengths, 2);
CGContextMoveToPoint(context, 0.0, 40.0);
CGContextAddLineToPoint(context, 310.0, 40.0);
CGContextStrokePath(context);
CGContextSetLineDash(context, 8, lengths, 2);
CGContextMoveToPoint(context, 0.0, 60.0);
CGContextAddLineToPoint(context, 310.0, 60.);
CGContextStrokePath(context);
}
由于lengths值为{10,5},第一条线就是绘制10,跳过5,反复绘制。
第二条线的phase值为5,则首先绘制【10减去5】,再跳过5,绘制10,反复绘制。
第三条给也如此,先绘制2,再跳过5,如此反复。
- iOS 用CGContextRef画虚线
- iOS开发 CGContextRef之画虚线
- CGContextRef 画直线、画虚线
- IOS用CGContextRef画各种图形
- IOS用CGContextRef画各种图形
- IOS用CGContextRef画各种图形
- IOS用CGContextRef画各种图形
- IOS用CGContextRef画各种图形
- IOS用CGContextRef画各种图形
- IOS用CGContextRef画各种图形
- iOS用CGContextRef画图
- iOS用CGContextRef画图
- iOS 画虚线
- iOS 画虚线 cgcontext
- iOS画虚线
- iOS 画虚线
- iOS 画虚线
- iOS:绘图画虚线
- Oracle 两张表死锁
- weka源码导入eclipse
- 技术博客收藏
- android 基础(一):activity启动方式standard、singleTop、singleTaste、singleInstance
- zTree -- jQuery 树插件在oneThink中的应用
- iOS 用CGContextRef画虚线
- 基础篇_浅谈Android 布局
- pymssql登陆本地sql server 服务器
- 理解JavaScript中的事件轮询
- 算法导论学习笔记(一)排序算法之插入排序
- PB动态SQL语句
- 【JAVA/读书随笔】Chapter 22 算法效率
- 苹果设备3.5英寸,4英寸,4.7英寸,5.5英寸屏幕像素指南
- 配置https双向认证过程实战(tomcat和浏览器交互)