@@ -35,4 +35,32 @@ - (UIImage *)imageMaskedWithColor:(UIColor *)maskColor {
3535 return newImage;
3636}
3737
38+ + (UIImage *)resizableImageWithColor : (UIColor *)color
39+ cornerRadius : (CGFloat)cornerRadius {
40+
41+ CGFloat scale = UIScreen.mainScreen .scale ;
42+ CGFloat size = 1.0 + 2 * cornerRadius;
43+ UIGraphicsBeginImageContextWithOptions (CGSizeMake (size, size), NO , scale);
44+ CGContextRef context = UIGraphicsGetCurrentContext ();
45+ CGContextSetFillColorWithColor (context, color.CGColor );
46+ CGMutablePathRef path = CGPathCreateMutable ();
47+ CGPathMoveToPoint (path, NULL , cornerRadius + 1.0 , 0.0 );
48+ CGPathAddArcToPoint (path, NULL , size, 0.0 , size, cornerRadius, cornerRadius);
49+ CGPathAddLineToPoint (path, NULL , size, cornerRadius + 1.0 );
50+ CGPathAddArcToPoint (path, NULL , size, size, cornerRadius + 1.0 , size, cornerRadius);
51+ CGPathAddLineToPoint (path, NULL , cornerRadius, size);
52+ CGPathAddArcToPoint (path, NULL , 0.0 , size, 0.0 , cornerRadius + 1.0 , cornerRadius);
53+ CGPathAddLineToPoint (path, NULL , 0.0 , cornerRadius);
54+ CGPathAddArcToPoint (path, NULL , 0.0 , 0.0 , cornerRadius, 0.0 , cornerRadius);
55+ CGPathCloseSubpath (path);
56+ CGContextAddPath (context, path);
57+ CGPathRelease (path);
58+ CGContextFillPath (context);
59+ UIImage *image = UIGraphicsGetImageFromCurrentImageContext ();
60+ UIGraphicsEndImageContext ();
61+
62+ return [image resizableImageWithCapInsets: UIEdgeInsetsMake (cornerRadius, cornerRadius, cornerRadius, cornerRadius)
63+ resizingMode: UIImageResizingModeStretch];
64+ }
65+
3866@end
0 commit comments