画虚线的方法 (记录)

+(UIImage *)lineWithImageView:(UIImageView *)imageView{

    CGFloat width = imageView.frame.size.width;

    CGFloat height = imageView.frame.size.height;

    UIGraphicsBeginImageContext(imageView.frame.size);

    [imageView.image drawInRect:CGRectMake(0, 0, width, height)];

    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);

    CGFloat lengths[] = {5,2};

    CGContextRef line = UIGraphicsGetCurrentContext();

    CGContextSetStrokeColorWithColor(line, [UIColor colorWithRed:128/255.0 green:128/255.0 blue:128/255.0 alpha:0.6].CGColor);

    CGContextSetLineDash(line, 0, lengths, 1);

    CGContextMoveToPoint(line, 0, 1);

    CGContextAddLineToPoint(line, width-10, 1);

    CGContextStrokePath(line);

    return  UIGraphicsGetImageFromCurrentImageContext();

}

原文地址:https://www.cnblogs.com/wj0920wjx/p/8807262.html