RoundedCorners.swift 655 B

123456789101112131415161718192021222324252627
  1. //
  2. // RoundedCorners.swift
  3. // LoopKitUI
  4. //
  5. // Created by Michael Pangburn on 5/7/20.
  6. // Copyright © 2020 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. extension View {
  10. func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View {
  11. clipShape(RoundedCorners(radius: radius, corners: corners))
  12. }
  13. }
  14. struct RoundedCorners: Shape {
  15. var radius: CGFloat
  16. var corners: UIRectCorner = .allCorners
  17. func path(in rect: CGRect) -> Path {
  18. let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
  19. return Path(path.cgPath)
  20. }
  21. }