Compose SwiftUIv0.4.0
esc
GuideAPIGitHub
View modifier

foregroundStyle(_:)

Sets the color or style of a view's foreground.

iOS 17.0+macOS 14.0+tvOS 17.0+watchOS 10.0+
fun Modifier.foregroundStyle(style: ShapeStyle): Modifier

Overview

It accepts any shape style: a Color, a gradient, or a hierarchical style such as ShapeStyle.secondary.

Text("Updated 2 min ago", modifier = Modifier.foregroundStyle(ShapeStyle.secondary))

This is the Kotlin form of SwiftUI View.foregroundStyle(_:): SwiftUI documentation. In Swift it reads:

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

Topics

Overloads

fun Modifier.foregroundStyle(primary: ShapeStyle, secondary: ShapeStyle, tertiary: ShapeStyle): Modifier
SwiftUI View.foregroundStyle(_:_:_:)
fun Modifier.foregroundStyle(style: ShapeStyle): Modifier
SwiftUI View.foregroundStyle(_:)
fun Modifier.foregroundStyle(primary: ShapeStyle, secondary: ShapeStyle): Modifier
SwiftUI View.foregroundStyle(_:_:)