Mathias Bak
Mathias Bak

Reputation: 5115

How do I refer to the accent color in a SwiftUI component?

In the top level of my app I set .accentColor(.mySpecialColor). All buttons and active elements then behave nicely and use the color. But how do when I write my own component that also adheres to the accent color?

An example could be

struct MyActiveView: View {
  var body: some View {
    Text("Hello")
      .foregroundColor( ?? ) // How do I refer to accent color here?
  }
}

Upvotes: 1

Views: 64

Answers (1)

Asperi
Asperi

Reputation: 257493

Use as follows

struct MyActiveView: View {
  var body: some View {
    Text("Hello")
      .foregroundColor(Color.accentColor)   // << here !!
  }
}

Upvotes: 1

Related Questions