//画虚线
-
(UIImage *)drawLineWithView:(UIImageView *)imageView lineColor:(UIColor *)lineColor {
[imageView layoutIfNeeded];
// 开始划线 划线的frame
UIGraphicsBeginImageContext(imageView.frame.size);[imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)];
// 获取上下文
CGContextRef line = UIGraphicsGetCurrentContext();// 设置线条终点的形状
CGContextSetLineCap(line, kCGLineCapRound);
// 设置虚线的长度 和 间距
CGFloat lengths[] = {3,3};CGContextSetStrokeColorWithColor(line, lineColor.CGColor);
// 开始绘制虚线
CGContextSetLineDash(line, 0, lengths, 2);CGContextMoveToPoint(line, 0.0, 2.0);
CGContextAddLineToPoint(line, 300, 2.0);
CGContextStrokePath(line);
// UIGraphicsGetImageFromCurrentImageContext()返回的就是image
return UIGraphicsGetImageFromCurrentImageContext();
}
网友评论