Last active
January 3, 2023 22:45
-
-
Save mdb1/3e7df86735db7d3417c57878e286e77a to your computer and use it in GitHub Desktop.
RoundedOverlayBorder modifier
This file contains hidden or 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
| /// Extension to apply a RoundedOverlayBorder modifier. | |
| extension View { | |
| /// Adds a rounded overlay border to the view. | |
| func roundedOverlayBorder( | |
| cornerRadius: CGFloat, | |
| color: Color = .gray, | |
| lineWidth: CGFloat = 1 | |
| ) -> some View { | |
| modifier( | |
| RoundedOverlayBorderModifier( | |
| cornerRadius: cornerRadius, | |
| color: color, | |
| lineWidth: lineWidth | |
| ) | |
| ) | |
| } | |
| } | |
| /// A modifier that adds a `rounded rectangle` overlay border to the view. | |
| struct RoundedOverlayBorderModifier: ViewModifier { | |
| private var cornerRadius: CGFloat | |
| private var color: Color | |
| private var lineWidth: CGFloat | |
| init( | |
| cornerRadius: CGFloat, | |
| color: Color, | |
| lineWidth: CGFloat = 1 | |
| ) { | |
| self.cornerRadius = cornerRadius | |
| self.color = color | |
| self.lineWidth = lineWidth | |
| } | |
| func body(content: Content) -> some View { | |
| content.overlay( | |
| RoundedRectangle(cornerRadius: cornerRadius) | |
| .stroke(color, lineWidth: lineWidth) | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment