Skip to content

Commit

Permalink
Create PartlyRoundedCornerView.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuzukihashi committed Apr 6, 2024
1 parent d898892 commit c1c4eb5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Sources/TsuzuKit/Representable/PartlyRoundedCornerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/// https://qiita.com/chocoyama/items/1cb7040f0e717406a6f4
/// Useage
/// .cornerRadius(20, maskedCorners: [.layerMinXMinYCorner, .layerMaxXMinYCorner])

import SwiftUI

public struct PartlyRoundedCornerView: UIViewRepresentable {
let cornerRadius: CGFloat
let maskedCorners: CACornerMask

public func makeUIView(context: UIViewRepresentableContext<PartlyRoundedCornerView>) -> UIView {
let uiView = UIView()
uiView.layer.cornerRadius = cornerRadius
uiView.layer.maskedCorners = maskedCorners
uiView.backgroundColor = .white
return uiView
}

public func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<PartlyRoundedCornerView>) {
}
}

public struct PartlyRoundedCornerModifier: ViewModifier {
let cornerRadius: CGFloat
let maskedCorners: CACornerMask

public func body(content: Content) -> some View {
content.mask(PartlyRoundedCornerView(cornerRadius: self.cornerRadius, maskedCorners: self.maskedCorners))
}
}

extension View {
public func cornerRadius(_ radius: CGFloat, maskedCorners: CACornerMask) -> some View {
self.modifier(PartlyRoundedCornerModifier(cornerRadius: radius, maskedCorners: maskedCorners))
}
}

0 comments on commit c1c4eb5

Please sign in to comment.