Swift Image(画像)のサイズを変更するサンプル

環境
Swift version 5.2.3 (swift-5.2.3-RELEASE)

構文

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Image("image")
.resizable()
.frame(width: 横幅, height: 高さ)
Image("image") .resizable() .frame(width: 横幅, height: 高さ)
Image("image")
    .resizable()
    .frame(width: 横幅, height: 高さ)

Imageにframe修飾子を付与します。
frame修飾子の引数「width」には横幅、引数「height」には高さを指定します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
struct ContentView: View {
var body: some View {
VStack {
Image("samplephoto")
.resizable()
.frame(width: 200, height: 100)
}
}
}
struct ContentView: View { var body: some View { VStack { Image("samplephoto") .resizable() .frame(width: 200, height: 100) } } }
struct ContentView: View {
    var body: some View {
        VStack {
           Image("samplephoto")
                .resizable()
                .frame(width: 200, height: 100)
        }
    }
}

 

IT

Posted by arkgame