-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create PartlyRoundedCornerView.swift
- Loading branch information
1 parent
d898892
commit c1c4eb5
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
Sources/TsuzuKit/Representable/PartlyRoundedCornerView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |