项目中遇到需要绘制虚线的功能
上网找了下代码,感谢网上的开发者分享
贴在这里以作记录
过程:
1. 新建UIImageView,用于展示所画的虚线
2. 设置虚线每画多少个point就空出多少个point
3. 设置线条颜色;KIT_RGBA(200, 200, 200, 255)是颜色函数的宏定义,返回CGColor对象
4. 设置线条宽度
5.开始画线,移动到起点,画到终点
6.结束画线,通过UIGraphicsGetImageFromCurrentImageContext()返回UIImage对象
// 画虚线
UIImageView *dashedImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, RECEIVE_INFO_TITLE_CELL_HEIGHT-1, CELL_WIDTH, 1)];
UIGraphicsBeginImageContext(dashedImageView.frame.size); <span style="white-space:pre"> </span>// 开始画线
CGContextRef line = UIGraphicsGetCurrentContext();
CGContextSetLineCap(lin