带边框的虚线

/*这是方法的实现

@param size 需要虚线边框视图的大小

@param color 边框颜色@param borderWidth 边框粗细

@return 返回一张带边框的图片

+ (UIImage *)imageWithSize:(CGSize)size borderColor:(UIColor *)color borderWidth:(CGFloat)borderWidth

{

UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);

[[UIColor clearColor] set];

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextBeginPath(context);

CGContextSetLineWidth(context, borderWidth);

CGContextSetStrokeColorWithColor(context, color.CGColor);

CGFloat lengths[] = { 3, 1 };

CGContextSetLineDash(context, 0, lengths, 1);

CGContextMoveToPoint(context, 0.0, 0.0);

CGContextAddLineToPoint(context, size.width, 0.0);

CGContextAddLineToPoint(context, size.width, size.height);

CGContextAddLineToPoint(context, 0, size.height);

CGContextAddLineToPoint(context, 0.0, 0.0);

CGContextStrokePath(context);

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return image;

}

你可能感兴趣的:(带边框的虚线)