「Swift」Buttonビューのボタンタップのサンプル
書式
Button(“ボタン名") {
//ボタンがタップされた時の処理コード
}
使用例
struct ContentView: View {
var body: some View {
Button("テスト") {
print("テストボタンがタップされました")
}
.foregroundColor(Color.green)
.padding(15)
.background(Color.yellow)
}
}
結果
「テスト」ボタンをタップすると、print()を実行してメッセージを出力します。