Created
October 9, 2023 02:29
-
-
Save antokne/6bb13b09de4ad9a1f0cd5af93c29913e to your computer and use it in GitHub Desktop.
Test for colorScheme env variable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
@Environment(\.colorScheme) var colorScheme: ColorScheme | |
var body: some View { | |
VStack { | |
Image(systemName: "globe") | |
.imageScale(.large) | |
.foregroundStyle(.tint) | |
Text("Hello, world!") | |
} | |
.padding() | |
.onChange(of: colorScheme) { newValue in | |
print("colorScheme [\(colorScheme)] changed to \(newValue)") | |
} | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running and then putting into the background gets the following output:
or vice versa depending on what your current mode is.