SwiftUI_visionOS_Note

Adapting Dark Mode in visionOS??

Mar 7, 2024
1 min read|

VisionOS’s default colour scheme is “Default”

We can change how it seems under preview by adding

.preferredColorScheme(.light)

or we can use the adaptive colour in assets

               Text("ADAPTIVE")
                   .foregroundStyle(Color("AdaptiveColor"))
swift

or we can create an enviroment variable to make it locally adaptive

@Environment(\.colorScheme) var colorScheme

Text("LOCALLY ADAPTIVE")
		.foregroundStyle(colorScheme == .light ? .green : .yellow)
swift

when it’s light mode. change the colour to green, or yellow.

Subscribe to our newsletter

Get the latest news and updates from our team