跳转至
Structure

ForegroundStyle

A ShapeStyle that shows the correct fill for the foreground based on the current context.

Declaration

@frozen struct ForegroundStyle

Overview

For example, to create a square view with a ForegroundStyle:

struct ForegroundStyleRectangle: View {
    var body: some View {
        Rectangle()
            .fill(ForegroundStyle())
            .frame(width: 150, height: 150)
            .foregroundColor(Color.pink)
    }
}
ForegroundStyle Example 1

Note:

  • ForegroundStyle is typically the default ShapeStyle, so it is rare to explicitly need it.

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


Initializer

init() Creates a foreground style.