.tint()

extrymes's avatar
Published Nov 22, 2023
Contribute to Docs

The .tint() modifier sets the tint color displayed in a view.

Syntax

Button("This is a button")
  .tint(color)

The .tint() applies the color to the Button which conforms it to the View protocol.

Example

struct ContentView: View {
var body: some View {
Button("This is a button")
.tint(.blue)
}
}

In the above example, the .tint() modifier with the .blue parameter is called on the Button view. This applies the blue tint color to the button.

This will display the following:

SwiftUI Button with blue tint color

Note: When a tint is applied to a view hierarchy, it only affects the text inside controls, like buttons and links, not plain Text views.

All contributors

Contribute to Docs

Learn SwiftUI on Codecademy