Contents

accentColor(_:)

Sets the accent color for this view and the views it contains.

Declaration

nonisolated func accentColor(_ accentColor: Color?) -> some View

Parameters

  • accentColor:

    The color to use as an accent color. Set the value to nil to use the inherited accent color.

Discussion

Use accentColor(_:) when you want to apply a broad theme color to your app’s user interface. Some styles of controls use the accent color as a default tint color.

In the example below, the outer VStack contains two child views. The first is a button with the default accent color. The second is a VStack that contains a button and a slider, both of which adopt the purple accent color of their containing view. Note that the Text element used as a label alongside the Slider retains its default color.

VStack(spacing: 20) {
    Button(action: {}) {
        Text("Regular Button")
    }
    VStack {
        Button(action: {}) {
            Text("Accented Button")
        }
        HStack {
            Text("Accented Slider")
            Slider(value: $sliderValue, in: -100...100, step: 0.1)
        }
    }
    .accentColor(.purple)
}

[Image]

See Also

Graphics and rendering modifiers