Instance Method

foregroundColor(_:)

Sets the color of the text displayed by this view.

Declaration

func foregroundColor(_ color: Color?) -> some View

Parameters

color

The color 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 color 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").foregroundColor(.red)
    Text("Green").foregroundColor(.green)
    Text("Blue").foregroundColor(.blue)
}

Three text views arranged horizontally, each containing the name of a color displayed in that color.

See Also

Setting View Colors

func accentColor(Color?) -> View

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