Skip to content

Instantly share code, notes, and snippets.

@enomoto
Last active September 20, 2022 00:35
Show Gist options
  • Save enomoto/a2b4453d015e9e054a9d0e73bf8c0227 to your computer and use it in GitHub Desktop.
Save enomoto/a2b4453d015e9e054a9d0e73bf8c0227 to your computer and use it in GitHub Desktop.
Sample for simple modifier
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
globeLabel
.padding()
.mainCell() // Applying quite simple custom modifier
}
}
private var globeLabel: some View {
Label("Hello, world!", systemImage: "globe")
}
}
import SwiftUI
extension View {
func mainCell() -> some View {
background(
Color.cyan.opacity(0.1)
)
.cornerRadius(20)
}
}
// or implement like this ...
extension View {
func mainCell2() -> some View {
modifier(MainCellModifier())
}
}
private struct MainCellModifier: ViewModifier {
func body(content: Content) -> some View {
content.background(
Color.cyan.opacity(0.1)
)
.cornerRadius(20)
}
}
@enomoto
Copy link
Author

enomoto commented Sep 20, 2022

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