18
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【SwiftUI】画像のリサイズ

Last updated at Posted at 2019-11-12

画像の表示

struct ContentView: View {
    var body: some View {
        Image("Image", bundle: .main)
    }
}
スクリーンショット 2019-11-12 15.03.57.png

大きすぎるのでリサイズ

struct ContentView: View {
    var body: some View {
        Image("Image", bundle: .main)
            .frame(width: 50.0, height: 50.0, alignment: .leading)
    }
}

ちゃんとリサイズされません

スクリーンショット 2019-11-12 15.05.16.png

.resizable()を付ける

Image をリサイズする際には .resizable() をつけなければならないみたいです。

struct ContentView: View {
    var body: some View {
        Image("Image", bundle: .main)
            .resizable()
            .frame(width: 50.0, height: 50.0, alignment: .leading)
    }
}
スクリーンショット 2019-11-12 15.05.34.png

これでリサイズされました。

18
5
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
18
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?