-
Bring widgets to new places
The widget ecosystem is expanding: Discover how you can use the latest WidgetKit APIs to make your widget look great everywhere. We'll show you how to identify your widget's background, adjust layout dynamically, and prepare colors for vibrant rendering so that your widget can sit seamlessly in any environment.
Chapitres
- 0:00 - Introduction
- 1:44 - Transition to content margins
- 3:00 - Add a removable background
- 4:31 - Dynamically adjust layout
- 6:00 - Prepare for vibrant rendering
Ressources
Vidéos connexes
WWDC23
WWDC22
-
Rechercher dans cette vidéo…
-
-
2:08 - SafeAreasWidget
struct SafeAreasWidgetView: View { @Environment(\.widgetContentMargins) var margins var body: some View { ZStack { Color.blue Group { Color.lightBlue Text("Hello, world!") } .padding(margins) } } } struct SafeAreasWidget: Widget { var body: some WidgetConfiguration { StaticConfiguration(...) {_ in SafeAreasWidgetView() } .contentMarginsDisabled() } } -
3:19 - EmojiRangerWidget systemSmall
struct EmojiRangerWidgetEntryView: View { var entry: Provider.Entry @Environment(\.widgetFamily) var family var body: some View { switch family { case .systemSmall: ZStack { AvatarView(entry.hero) .widgetURL(entry.hero.url) .foregroundColor(.white) } .containerBackground(for: .widget) { Color.gameBackground } } // additional cases } } -
3:48 - EmojiRangerWidget accessoryRectangular
var body: some View { switch family { case .accessoryRectangular: HStack(alignment: .center, spacing: 0) { VStack(alignment: .leading) { Text(entry.hero.name) .font(.headline) .widgetAccentable() Text("Level \(entry.hero.level)") Text(entry.hero.fullHealthDate, style: .timer) }.frame(maxWidth: .infinity, alignment: .leading) Avatar(hero: entry.hero, includeBackground: false) } .containerBackground(for: .widget) { Color.gameBackground } // additional cases } -
4:22 - PhotoWidget
struct PhotoWidget: Widget { public var body: some WidgetConfiguration { StaticConfiguration(...) { entry in PhotoWidgetView(entry: entry) } .containerBackgroundRemovable(false) } }
-