Skip to content

iOS14 WidgetKitでサイズを限定する方法

iOS14から使えるようになった、Widgetですが、サイズがsmall、medium、largeの3つの大きさが用意されています。Widgetを実装する際は、全てのサイズに対応するか、任意のサイズのみにするように設定できます。

実装方法は、以下のように、使用したいサイズをsupportedFamiliesに指定するだけです。

.supportedFamilies([.systemSmall, .systemMedium])
struct EmojiRangerWidget: Widget {
    private let kind: String = "EmojiRangerWidget"

    public var body: some WidgetConfiguration {
        IntentConfiguration(kind: kind, intent: DynamicCharacterSelectionIntent.self, provider: Provider()) { entry in
            EmojiRangerWidgetEntryView(entry: entry)
        }
        .configurationDisplayName("Ranger Detail")
        .description("See your favorite ranger.")
        .supportedFamilies([.systemSmall, .systemMedium])
    }
}

https://developer.apple.com/documentation/widgetkit/staticconfiguration/supportedfamilies(_:)

https://developer.apple.com/documentation/widgetkit/building_widgets_using_widgetkit_and_swiftui

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です