Hi all,
I have a semi-working approach to manually toggle Dark Mode across an app in SwiftUI. The toggle overrides the System dark mode. However, does anyone know how I can add a button for giving an option to revert to System light/dark mode instead?
I am running Xcode beta in iOS14. See code below.
Many thanks!
Settings toggle
@AppStorage("isDarkMode") var isDarkMode: Bool = true
var body: some View {
Form {
Toggle(isOn: $isDarkMode) {
Text("Darkmode")
}
}
Dark mode modifier definition
public struct DarkModeViewModifier: ViewModifier {
@AppStorage("isDarkMode") var isDarkMode: Bool = true
public func body(content: Content) -> some View {
content
.environment(\.colorScheme, isDarkMode ? .dark : .light)
.preferredColorScheme(isDarkMode ? .dark : .light)
}
}
This is the how I applied the dark mode modifier across the app
@main
struct Lab_mate_2App: App {
var body: some Scene {
WindowGroup {
ContentView()
.modifier(DarkModeViewModifier())
}
}
}
Post
Replies
Boosts
Views
Activity
Hi all,
I am trying to implement a Copy Text option for read only text output just like the iOS calculator output using SwiftUI 2.0 (Swift 5.3)
I want the user to be able to copy the text, and nothing more. Surprisingly simple yet I can't figure out how to do it any help greatly appreciated!
Thanks.