-
Go further with Complications in WidgetKit
Discover how you can use WidgetKit to create beautiful complications on watch faces. We'll introduce you to the watchOS-specific features found in WidgetKit, and help you migrate from existing ClockKit complications.
For more on WidgetKit, watch “Complications and Widgets: Reloaded” from WWDC22.Recursos
- Migrating ClockKit complications to WidgetKit
- Creating accessory widgets and watch complications
- Emoji Rangers: Supporting Live Activities, interactivity, and animations
- WidgetKit
Vídeos relacionados
Tech Talks
WWDC22
WWDC20
-
Buscar neste vídeo...
-
-
3:06 - Large Corner
struct CornerView: View { let value: Double var body: some View { ZStack { AccessoryWidgetBackground() Image(systemName: "cup.and.saucer.fill") .font(.title.bold()) .widgetAccentable() } } } -
3:27 - Corner with Gauge
struct CornerView: View { let value: Double var body: some View { ZStack { AccessoryWidgetBackground() Image(systemName: "cup.and.saucer.fill") .font(.title.bold()) .widgetAccentable() } .widgetLabel { Gauge(value: value, in: 0...500) { Text("MG") } currentValueLabel: { Text("\(Int(value))") } minimumValueLabel: { Text("0") } maximumValueLabel: { Text("500") } } } } -
4:24 - Circular Gauge
struct CircularView: View { let value: Double var body: some View { Gauge(value: value, in: 0...500) { Text("MG") } currentValueLabel: { Text("\(Int(value))") } .gaugeStyle(.circular) } } -
4:34 - Circular Gauge with Widget Label
struct CircularView: View { let value: Double var body: some View { let mg = value.inMG() Gauge(value: value, in: 0...500) { Text("MG") } currentValueLabel: { Text("\(Int(value))") } .gaugeStyle(.circular) .widgetLabel { Text("\(mg, formatter: mgFormatter) Caffeine") } } var mgFormatter: Formatter { let formatter = MeasurementFormatter() formatter.unitOptions = [.providedUnit] return formatter } } extension Double { func inMG() -> Measurement<UnitMass> { Measurement<UnitMass>(value: self, unit: .milligrams) } } -
4:51 - Circular Stack with Widget Label
struct CircularView: View { let value: Double var body: some View { let mg = value.inMG() ZStack { AccessoryWidgetBackground() Image(systemName: "cup.and.saucer.fill") .font(.title.bold()) .widgetAccentable() } .widgetLabel { Text("\(mg, formatter: mgFormatter) Caffeine") } } var mgFormatter: Formatter { let formatter = MeasurementFormatter() formatter.unitOptions = [.providedUnit] return formatter } } extension Double { func inMG() -> Measurement<UnitMass> { Measurement<UnitMass>(value: self, unit: .milligrams) } } -
5:12 - Circular Stack or Gauge
struct CircularView: View { let value: Double @Environment(\.showsWidgetLabel) var showsWidgetLabel var body: some View { let mg = value.inMG() if showsWidgetLabel { ZStack { AccessoryWidgetBackground() Image(systemName: "cup.and.saucer.fill") .font(.title.bold()) .widgetAccentable() } .widgetLabel { Text("\(mg, formatter: mgFormatter) Caffeine") } } else { Gauge(value: value, in: 0...500) { Text("MG") } currentValueLabel: { Text("\(Int(value))") } .gaugeStyle(.circular) } } var mgFormatter: Formatter { let formatter = MeasurementFormatter() formatter.unitOptions = [.providedUnit] return formatter } } extension Double { func inMG() -> Measurement<UnitMass> { Measurement<UnitMass>(value: self, unit: .milligrams) } } -
9:47 - Widget Migrator
var widgetMigrator: CLKComplicationWidgetMigrator { self } -
9:56 - Static Migration Configuration
func widgetConfiguration(from complicationDescriptor: CLKComplicationDescriptor) async -> CLKComplicationWidgetMigrationConfiguration? { CLKComplicationStaticWidgetMigrationConfiguration(kind: "CoffeeTracker", extensionBundleIdentifier: widgetBundle) } -
10:03 - Intent Migration Configuration
func widgetConfiguration(from complicationDescriptor: CLKComplicationDescriptor) async -> CLKComplicationWidgetMigrationConfiguration? { CLKComplicationIntentWidgetMigrationConfiguration(kind: "CoffeeTracker", extensionBundleIdentifier: widgetBundle, intent: intent, localizedDisplayName: "Coffee Tracker") }
-