SwiftUI .tint()

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

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

  • Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.
    • Includes 7 Courses
    • With Certificate
    • Beginner Friendly.
      13 hours
  • A powerful programming language developed by Apple for iOS, macOS, and more.
    • Beginner Friendly.
      12 hours

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

  • Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.
    • Includes 7 Courses
    • With Certificate
    • Beginner Friendly.
      13 hours
  • A powerful programming language developed by Apple for iOS, macOS, and more.
    • Beginner Friendly.
      12 hours