Swift Rectangleにアスペクト比を設定するサンプル

環境
Swift version 5.2.3 (swift-5.2.3-RELEASE)
Ubuntu 20.04.2 LTS

構文

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Rectangle()
.aspectRatio(アスペクト比, contentMode: .fit)
Rectangle() .aspectRatio(アスペクト比, contentMode: .fit)
Rectangle()
    .aspectRatio(アスペクト比, contentMode: .fit)

引数1: アスペクト比(横幅 ÷ 高さ)
引数2「.fit」を指定します
Rectangleにアスペクト比を設定するには、aspectRatio修飾子を使います。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
struct ContentView: View {
var body: some View {
VStack {
Rectangle()
.aspectRatio(1.3, contentMode: .fit)
}
}
}
struct ContentView: View { var body: some View { VStack { Rectangle() .aspectRatio(1.3, contentMode: .fit) } } }
struct ContentView: View {
    var body: some View {
        VStack {
            Rectangle()
                .aspectRatio(1.3, contentMode: .fit)
        }
    }
}

 

Swift

Posted by arkgame