LoginSignup
1
1

More than 1 year has passed since last update.

【SwiftUI】WidgetにURL画像を表示する

Posted at

はじめに

WidgetでURLの画像を表示したかったのですが、非同期処理はできないらしくAsyncImageを使うことができませんでした。
別の方法でURL画像を表示することができたので記録しておきます。

実装

if let url = URL(string: "https://sample.com/sample.png"),
   let imageData = try? Data(contentsOf: url),
   let uiImage = UIImage(data: imageData) {
    Image(uiImage: uiImage).resizable()
} else {
    Image("placeholder")
}

おわり

Widgetはちょっとクセがあって難しいです。。

1
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
1
1