Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import SwiftUI
struct BackgroundModifier: ViewModifier {
let colour: Color
func body(content: Content) -> some View {
ZStack {
colour
.edgesIgnoringSafeArea(.all)
content
}
}
}
extension View {
func applyBackground(colour: Color? = nil) -> some View {
modifier(BackgroundModifier(colour: colour ?? Colours.mainBackground))
}
}
@dchakarov
Copy link
Author

dchakarov commented Jan 7, 2021

Usage:

struct ContentView: View {
    var body: some View {
        Text("I love SwiftUI")
            .applyBackground(colour: .orange)
    }
}

@fassko
Copy link

fassko commented Jan 8, 2021

Such a great idea, thanks for showing this! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment