Answers for "how to check if there is dark mode code wise swiftui"

0

how to check if there is dark mode code wise swiftui

//You can use the colorScheme Environment Key

struct ContentView: View {
	
  @Environemnt(\.colorScheme) var colorScheme
  
  var body: some View {
    Text("Hello")
    .foregroundColor(colorScheme == .light ? .black : .white)
    
    //The tenary operator checks if the view is either in light mode or in dark mode
    //If it is in light mode, the font colour of the text would be black, otherwise it is white
  }
}
Posted by: Guest on October-24-2021

Code answers related to "how to check if there is dark mode code wise swiftui"

Code answers related to "Swift"

Browse Popular Code Answers by Language