@@ -57,25 +57,25 @@ extension UIView {
5757 backgroundColor: UIColor ,
5858 borderColor: UIColor ) -> UIImage {
5959 let sizeToFit = CGSize ( width: pixel ( Double ( self . bounds. size. width) ) , height: Double ( self . bounds. size. height) )
60- let halfBorderWidth = CGFloat ( borderWidth / 2.0 ) ;
60+ let halfBorderWidth = CGFloat ( borderWidth / 2.0 )
6161
6262 UIGraphicsBeginImageContextWithOptions ( sizeToFit, false , UIScreen . mainScreen ( ) . scale)
6363 let context = UIGraphicsGetCurrentContext ( )
6464
65- CGContextSetLineWidth ( context, borderWidth) ;
66- CGContextSetStrokeColorWithColor ( context, borderColor. CGColor) ;
67- CGContextSetFillColorWithColor ( context, backgroundColor. CGColor) ;
65+ CGContextSetLineWidth ( context, borderWidth)
66+ CGContextSetStrokeColorWithColor ( context, borderColor. CGColor)
67+ CGContextSetFillColorWithColor ( context, backgroundColor. CGColor)
6868
6969 let width = sizeToFit. width, height = sizeToFit. height
70- CGContextMoveToPoint ( context, width - halfBorderWidth, radius + halfBorderWidth) ; // 开始坐标右边开始
71- CGContextAddArcToPoint ( context, width - halfBorderWidth, height - halfBorderWidth, width - radius - halfBorderWidth, height - halfBorderWidth, radius) ; // 右下角角度
72- CGContextAddArcToPoint ( context, halfBorderWidth, height - halfBorderWidth, halfBorderWidth, height - radius - halfBorderWidth, radius) ; // 左下角角度
73- CGContextAddArcToPoint ( context, halfBorderWidth, halfBorderWidth, width - halfBorderWidth, halfBorderWidth, radius) ; // 左上角
74- CGContextAddArcToPoint ( context, width - halfBorderWidth, halfBorderWidth, width - halfBorderWidth, radius + halfBorderWidth, radius) ; // 右上角
70+ CGContextMoveToPoint ( context, width - halfBorderWidth, radius + halfBorderWidth) // 开始坐标右边开始
71+ CGContextAddArcToPoint ( context, width - halfBorderWidth, height - halfBorderWidth, width - radius - halfBorderWidth, height - halfBorderWidth, radius) // 右下角角度
72+ CGContextAddArcToPoint ( context, halfBorderWidth, height - halfBorderWidth, halfBorderWidth, height - radius - halfBorderWidth, radius) // 左下角角度
73+ CGContextAddArcToPoint ( context, halfBorderWidth, halfBorderWidth, width - halfBorderWidth, halfBorderWidth, radius) // 左上角
74+ CGContextAddArcToPoint ( context, width - halfBorderWidth, halfBorderWidth, width - halfBorderWidth, radius + halfBorderWidth, radius) // 右上角
7575
7676 CGContextDrawPath ( UIGraphicsGetCurrentContext ( ) , . FillStroke)
77- let output = UIGraphicsGetImageFromCurrentImageContext ( ) ;
78- UIGraphicsEndImageContext ( ) ;
77+ let output = UIGraphicsGetImageFromCurrentImageContext ( )
78+ UIGraphicsEndImageContext ( )
7979 return output
8080 }
8181}
@@ -87,6 +87,8 @@ extension UIImageView {
8787 :param: radius 圆角半径
8888 */
8989 override func kt_addCorner( radius radius: CGFloat ) {
90+ // 被注释的是图片添加圆角的 OC 写法
91+ // self.image = self.image?.imageAddCornerWithRadius(radius, andSize: self.bounds.size)
9092 self . image = self . image? . kt_drawRectWithRoundedCorner ( radius: radius, self . bounds. size)
9193 }
9294}
@@ -103,8 +105,8 @@ extension UIImage {
103105
104106 self . drawInRect ( rect)
105107 CGContextDrawPath ( UIGraphicsGetCurrentContext ( ) , . FillStroke)
106- let output = UIGraphicsGetImageFromCurrentImageContext ( ) ;
107- UIGraphicsEndImageContext ( ) ;
108+ let output = UIGraphicsGetImageFromCurrentImageContext ( )
109+ UIGraphicsEndImageContext ( )
108110
109111 return output
110112 }
0 commit comments