import SwiftUI
struct UserSettings {
var fontSize: CGFloat = 17
}
struct UserView: View {
@EnvironmentObject var userSettings: UserSettings
var body: some View {
VStack {
Text("Hello, World")
.font(.system(size: userSettings.fontSize))
Slider(value: $userSettings.fontSize, in: 10...30)
}
}
}
struct ContentView: View {
var body: some View {
UserView().environmentObject(UserSettings())
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter