A
Ash
Guest
Ash Asks: Im trying to make a picker style like the appearance picker in settings
I'm tying to make a picker style that looks like this
Here is the code for the theme
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
I'm tying to make a picker style that looks like this

Here is the code for the theme
Code:
@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
SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.