Declaration
compose().foregroundStyle(style: SwiftUI.ShapeStyle)nonisolated func foregroundStyle<S>(
_ style: S
) -> Text
where S : ShapeStyleParameters
style*SwiftUI.ShapeStyleThe 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)
}See also
More in Text modifiers.
- accessibilityHeadingSets the accessibility level of this heading.
- accessibilityLabelAdds a label to the view that describes its contents.
- accessibilityTextContentTypeSets an accessibility text content type.
- baselineOffsetSets the vertical offset for the text relative to its baseline.
- boldApplies a bold font weight to the text.
- fontSets the default font for text in the view.
- fontDesignSets the font design of the text.
- fontWeightSets the font weight of the text.
- fontWidthSets the font width of the text.
- italicApplies italics to the text.
- kerningSets the spacing, or kerning, between characters.
- monospacedModifies the font of the text to use the fixed-width variant of the current font, if possible.