LoginSignup
0
1

More than 1 year has passed since last update.

WidgetBundle

WidgetBundleを使うと、異なる種類のWidgetを追加できます。

公式の例にもありますが、こんな感じです。

@main
struct GameWidgets: WidgetBundle {

    var body: some Widget {
        GameStatusWidget()
        CharacterDetailWidget()
        LeaderboardWidget()
    }

}

ポイントは、
- @mainをつける
- WidgetBundleを継承する
- bodyの中で複数のWidgetを並べる

異なるWidgetを使うことで、異なるレイアウトのWidgetを作りやすくなりますね。

サンプルで作ったものはこちらになります。

@main
struct MyWidgets: WidgetBundle {
    var body: some Widget {
        FirstWidget()
        SecondWidget()
    }    
}

1つ目 2つ目
widgetbundle_first.png widgetbundle_second.png

参考

https://developer.apple.com/documentation/widgetkit/creating-a-widget-extension
https://developer.apple.com/documentation/SwiftUI/WidgetBundle

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1