Swift Buttonのサイズを設定するサンプル

環境
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
Button(action: {
//タップ処理コード
},label: {
Text("xxx")
})
.frame(width: 横幅, height: 高さ)
Button(action: { //タップ処理コード },label: { Text("xxx") }) .frame(width: 横幅, height: 高さ)
Button(action: {
     //タップ処理コード
},label:  {
            Text("xxx")
})
.frame(width: 横幅, height: 高さ)

「.frame」の引数「width」に横幅、引数「height」に高さを指定します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Button(action: {
print("press test")
},label: {
Text("Button")
.foregroundColor(Color.gary)
})
.frame(width: 150, height: 120)
.background(Color.red)
Button(action: { print("press test") },label: { Text("Button") .foregroundColor(Color.gary) }) .frame(width: 150, height: 120) .background(Color.red)
Button(action: {
    print("press test")
},label:  {
    Text("Button")
        .foregroundColor(Color.gary)
})
.frame(width: 150, height: 120)
.background(Color.red)

 

Swift

Posted by arkgame