I'm tying to make a picker style that looks like this
Here is the code for the theme
@main
struct GreenPowerPlantUniversalApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.modifier(DarkModeViewModifier())
}
}
class AppThemeViewModel: ObservableObject {
@AppStorage("appThemeSetting") var appThemeSetting = Appearance.system
}
struct DarkModeViewModifier: ViewModifier {
@ObservedObject var appThemeViewModel: AppThemeViewModel = AppThemeViewModel()
public func body(content: Content) -> some View {
content
.preferredColorScheme((appThemeViewModel.appThemeSetting == .system) ? .none : appThemeViewModel.appThemeSetting == .light ? .light : .dark)
}
}
enum Appearance: String, CaseIterable, Identifiable {
case system
case light
case dark
var id: String { self.rawValue }
}
}
struct ThemeSettingsView: View {
@AppStorage("appThemeSetting") var appThemeSetting = GreenPowerPlantUniversalApp.Appearance.system
var body: some View {
VStack {
Picker("Appearance", selection: $appThemeSetting) {
ForEach(GreenPowerPlantUniversalApp.Appearance.allCases) { appearance in
Text(appearance.rawValue.capitalized)
.tag(appearance)
}
}
.pickerStyle(SegmentedPickerStyle())
}.padding(.bottom, 100)
.padding(.horizontal, 20)
}
}
I just don't know where to start to create this as I'm a beginner to swift.
I think it would be best to make a picker style which I don't know how to do but anything to create this would work