[SwiftUI]Button(ボタン)の形を変えるには?

SwiftUI

どうも、ちょげ(@chogetarou)です。

Buttonの形を変える方法を紹介します。

スポンサーリンク

方法

インターフェース, インターネット, プログラム, ブラウザ, Www

Buttonの形を変えるには、clipShape修飾子を使います。

まず、ButtonにclipShape修飾子を付与します。

そして、clipShape修飾子の引数にButtonの形を指定します。

Button(・・・)
   .clipShape(Shape())

clipShape修飾子の引数に指定した形が、Buttonの形になります。

使用例

struct ContentView: View {
    var body: some View {
        VStack {
            Button("Button") {
                print("Tap")
            }
            .padding()
            .foregroundColor(.white)
            .background(.blue)
            .clipShape(Capsule())
        }
    }
}

コメント

タイトルとURLをコピーしました