-
-
Save sturdysturge/3e622876ba677bcf77982c73b1803b37 to your computer and use it in GitHub Desktop.
BluePaddingModifier
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
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
VStack { | |
Text("Blue") | |
.foregroundColor(.blue) | |
.padding(10) | |
Text("Blue") | |
.modifier(BluePaddingModifier(padding: 10)) | |
Text("Blue") | |
.blue(10) | |
Text("Blue") | |
.b(10) | |
} | |
} | |
} | |
struct BluePaddingModifier: ViewModifier { | |
let padding: CGFloat | |
func body(content: Content) -> some View { | |
content | |
.foregroundColor(.blue) | |
.padding(padding) | |
} | |
} | |
extension View { | |
func blue(_ padding: CGFloat) -> some View { | |
let modifier = BluePaddingModifier(padding: padding) | |
return ModifiedContent(content: self, modifier: modifier) | |
} | |
func b(_ padding: CGFloat) -> some View { | |
self.modifier(BluePaddingModifier(padding: padding)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment