onevcat 4 лет назад
Родитель
Сommit
40b1897d14

+ 2 - 0
Demo/Demo/Kingfisher-Demo/ViewControllers/ProcessorCollectionViewController.swift

@@ -42,6 +42,8 @@ class ProcessorCollectionViewController: UICollectionViewController {
         (ResizingImageProcessor(referenceSize: CGSize(width: 50, height: 50)), "Resizing"),
         (RoundCornerImageProcessor(radius: .point(20)), "Round Corner"),
         (RoundCornerImageProcessor(radius: .widthFraction(0.5), roundingCorners: [.topLeft, .bottomRight]), "Round Corner Partial"),
+        (BorderImageProcessor(border: .init(color: .systemBlue, lineWidth: 8)), "Border"),
+        (RoundCornerImageProcessor(radius: .widthFraction(0.2)) |> BorderImageProcessor(border: .init(color: .systemBlue, lineWidth: 12, radius: .widthFraction(0.2))), "Round Border"),
         (BlendImageProcessor(blendMode: .lighten, alpha: 1.0, backgroundColor: .red), "Blend"),
         (BlurImageProcessor(blurRadius: 5), "Blur"),
         (OverlayImageProcessor(overlay: .red, fraction: 0.5), "Overlay"),

+ 11 - 6
Sources/Image/ImageDrawing.swift

@@ -150,7 +150,7 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
                 rectPath.fill()
             }
             
-            let path = pathForRoundCorner(rect: rect, radius: radius, corners: corners, refRect: rect)
+            let path = pathForRoundCorner(rect: rect, radius: radius, corners: corners)
             context.addPath(path.cgPath)
             context.clip()
             base.draw(in: rect)
@@ -181,18 +181,21 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
     }
     
     #if os(macOS)
-    func pathForRoundCorner(rect: CGRect, radius: Radius, corners: RectCorner) -> NSBezierPath {
-        let path = NSBezierPath(roundedRect: rect, byRoundingCorners: corners, radius: radius)
+    func pathForRoundCorner(rect: CGRect, radius: Radius, corners: RectCorner, offsetBase: CGFloat = 0) -> NSBezierPath {
+        let path = NSBezierPath(roundedRect: rect, byRoundingCorners: corners, radius: radius - offsetBase / 2)
         path.windingRule = .evenOdd
         return path
     }
     #else
-    func pathForRoundCorner(rect: CGRect, radius: Radius, corners: RectCorner, refRect: CGRect) -> UIBezierPath {
+    func pathForRoundCorner(rect: CGRect, radius: Radius, corners: RectCorner, offsetBase: CGFloat = 0) -> UIBezierPath {
         let cornerRadius = radius.compute(with: rect.size)
         return UIBezierPath(
             roundedRect: rect,
             byRoundingCorners: corners.uiRectCorner,
-            cornerRadii: CGSize(width: cornerRadius / (refRect.width / rect.width), height: cornerRadius / (refRect.height / rect.height))
+            cornerRadii: CGSize(
+                width: cornerRadius - offsetBase / 2,
+                height: cornerRadius - offsetBase / 2
+            )
         )
     }
     #endif
@@ -380,13 +383,15 @@ extension KingfisherWrapper where Base: KFCrossPlatformImage {
             
             let strokeRect =  rect.insetBy(dx: border.lineWidth / 2, dy: border.lineWidth / 2)
             context.setStrokeColor(border.color.cgColor)
+            context.setAlpha(0.5)
             
             let line = pathForRoundCorner(
                 rect: strokeRect,
                 radius: border.radius,
                 corners: border.roundingCorners,
-                refRect: rect
+                offsetBase: border.lineWidth
             )
+            line.lineCapStyle = .square
             line.lineWidth = border.lineWidth
             line.stroke()