-2

I need to get the color scheme of the app to give some styles to a button content. I want to use it in a foregroundColor for example.

Samuel O.D.
  • 346
  • 2
  • 13

1 Answers1

1

It turns out it's pretty easy. You just need to do this:

@Environment(\.colorScheme) var colorScheme

Button {} label: {
    Text("Hello World")
}.foregroundColor(colorScheme == .dark ? .white : .black)
Samuel O.D.
  • 346
  • 2
  • 13