Contents

foregroundStyle(_:)

Sets the style of the text displayed by this view.

Declaration

nonisolated func foregroundStyle<S>(_ style: S) -> Text where S : ShapeStyle

Parameters

  • style:

    The style to use when displaying this text.

Return Value

A text view that uses the color value you supply.

Discussion

Use this method to change the rendering style of the text rendered by a text view.

For example, you can display the names of the colors red, green, and blue in their respective colors:

HStack {
    Text("Red").foregroundStyle(.red)
    Text("Green").foregroundStyle(.green)
    Text("Blue").foregroundStyle(.blue)
}

[Image]

See Also

Styling the view’s text