Contents

widgetRenderingMode

The widget’s rendering mode, based on where the system is displaying it.

Declaration

var widgetRenderingMode: WidgetRenderingMode { get set }

Discussion

You can read the rendering mode from the environment values using this key.

@Environment(\.widgetRenderingMode) var widgetRenderingMode

Then modify the widget’s appearance based on the mode.

var body: some View {
    ZStack {
       switch renderingMode {
        case .fullColor:
           Text("Full color")
        case .accented:
           ZStack {
               Circle(...)
               VStack {
                   Text("Accented")
                       .widgetAccentable()
                   Text("Normal")
               }
           }
        case .vibrant:
           Text("Full color")
        default:
           ...
        }
    }
}

See Also

Widgets