Skip to content

Commit

Permalink
extension(swifui): Allow corner radius for specific corners
Browse files Browse the repository at this point in the history
  • Loading branch information
dcvz committed Feb 14, 2024
1 parent 696818f commit 4d49039
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Sources/DSKit/SwiftUI/View+CornerRadius.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import SwiftUI

public extension View {
func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View {
clipShape( RoundedCorner(radius: radius, corners: corners) )
}
}

struct RoundedCorner: Shape {
var radius: CGFloat = .infinity
var corners: UIRectCorner = .allCorners

func path(in rect: CGRect) -> Path {
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
return Path(path.cgPath)
}
}

0 comments on commit 4d49039

Please sign in to comment.