带边框的虚线

/*这是方法的实现

@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;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容