When styling a view in SwiftUI, I can use .foregroundStyle
to apply a custom shape style, e.g.
view.foregroundStyle(.green)
Besides colors, I can use some more “advanced” shape styles. For example, .tint
refers to TintShapeStyle
rather than a color and only resolves to a concrete color internally:
view.foregroundStyle(.tint)
If I want to create a gradient for the foreground style, this is easy to do as well using predefined colors:
view.foregroundStyle(.linearGradient(colors: [.blue, .clear], startPoint: .top, endPoint: .bottom))
Unfortunately, I was not able to figure out how to use “dynamically resolved” colors (such as .tint
) when creating a gradient as there is no initializer that accepts a ShapeStyle
input (only a list of Color
is supported). Is there a way to do this in iOS 17?