|
@@ -337,10 +337,21 @@ static NSTimeInterval _yy_CGImageSourceGetGIFFrameDelayAtIndex(CGImageSourceRef
|
|
}
|
|
}
|
|
|
|
|
|
- (UIImage *)yy_imageByRoundCornerRadius:(CGFloat)radius {
|
|
- (UIImage *)yy_imageByRoundCornerRadius:(CGFloat)radius {
|
|
- return [self yy_imageByRoundCornerRadius:radius corners:UIRectCornerAllCorners borderWidth:0];
|
|
|
|
|
|
+ return [self yy_imageByRoundCornerRadius:radius borderWidth:0 borderColor:nil];
|
|
}
|
|
}
|
|
|
|
|
|
-- (UIImage *)yy_imageByRoundCornerRadius:(CGFloat)radius corners:(UIRectCorner)corners borderWidth:(CGFloat)borderWidth {
|
|
|
|
|
|
+- (UIImage *)yy_imageByRoundCornerRadius:(CGFloat)radius
|
|
|
|
+ borderWidth:(CGFloat)borderWidth
|
|
|
|
+ borderColor:(UIColor *)borderColor {
|
|
|
|
+ return [self yy_imageByRoundCornerRadius:radius corners:UIRectCornerAllCorners borderWidth:borderWidth borderColor:borderColor borderLineJoin:kCGLineJoinMiter];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (UIImage *)yy_imageByRoundCornerRadius:(CGFloat)radius
|
|
|
|
+ corners:(UIRectCorner)corners
|
|
|
|
+ borderWidth:(CGFloat)borderWidth
|
|
|
|
+ borderColor:(UIColor *)borderColor
|
|
|
|
+ borderLineJoin:(CGLineJoin)borderLineJoin {
|
|
|
|
+
|
|
UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
|
|
UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
|
|
CGContextRef context = UIGraphicsGetCurrentContext();
|
|
CGContextRef context = UIGraphicsGetCurrentContext();
|
|
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
|
|
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
|
|
@@ -349,9 +360,28 @@ static NSTimeInterval _yy_CGImageSourceGetGIFFrameDelayAtIndex(CGImageSourceRef
|
|
|
|
|
|
CGFloat minSize = MIN(self.size.width, self.size.height);
|
|
CGFloat minSize = MIN(self.size.width, self.size.height);
|
|
if (borderWidth < minSize / 2) {
|
|
if (borderWidth < minSize / 2) {
|
|
- [[UIBezierPath bezierPathWithRoundedRect:CGRectInset(rect, borderWidth, borderWidth) byRoundingCorners:corners cornerRadii:CGSizeMake(radius, borderWidth)] addClip];
|
|
|
|
|
|
+ UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectInset(rect, borderWidth, borderWidth) byRoundingCorners:corners cornerRadii:CGSizeMake(radius, borderWidth)];
|
|
|
|
+ [path closePath];
|
|
|
|
+
|
|
|
|
+ CGContextSaveGState(context);
|
|
|
|
+ [path addClip];
|
|
CGContextDrawImage(context, rect, self.CGImage);
|
|
CGContextDrawImage(context, rect, self.CGImage);
|
|
|
|
+ CGContextRestoreGState(context);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (borderColor && borderWidth < minSize / 2 && borderWidth > 0) {
|
|
|
|
+ CGFloat strokeInset = (floor(borderWidth * self.scale) + 0.5) / self.scale;
|
|
|
|
+ CGRect strokeRect = CGRectInset(rect, strokeInset, strokeInset);
|
|
|
|
+ CGFloat strokeRadius = radius > self.scale / 2 ? radius - self.scale / 2 : 0;
|
|
|
|
+ UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:strokeRect byRoundingCorners:corners cornerRadii:CGSizeMake(strokeRadius, borderWidth)];
|
|
|
|
+ [path closePath];
|
|
|
|
+
|
|
|
|
+ path.lineWidth = borderWidth;
|
|
|
|
+ path.lineJoinStyle = borderLineJoin;
|
|
|
|
+ [borderColor setStroke];
|
|
|
|
+ [path stroke];
|
|
|
|
+ }
|
|
|
|
+
|
|
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
|
|
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
|
|
UIGraphicsEndImageContext();
|
|
UIGraphicsEndImageContext();
|
|
return image;
|
|
return image;
|