有內邊距的button
第一種方式,這種方式不太好,不能響應整個背景范圍的點擊
HStack(alignment: VerticalAlignment.center, spacing: nil, content: {
Button("按鈕測試") {
print("按鈕點擊事件")
}.buttonStyle(PlainButtonStyle())
.border(Color.black, width: 1)
}).padding(EdgeInsets(top: 5, leading: 10, bottom: 5, trailing: 10))
.background(Color.yellow)
第二種方式,比較可響應整個點擊區域
Button {
print("有內邊距的button點擊")
} label: {
HStack(){
Text("有內邊距的button")
}.padding(EdgeInsets(top: 5, leading: 10, bottom: 5, trailing: 10))
.background(Color.yellow)
}
其他button樣式
Button("PlainButtonStyle") {
print("PlainButtonStyle點擊事件")
}.buttonStyle(PlainButtonStyle())
.border(Color.black, width: 1)
.background(Color.yellow)
Button("BorderlessButtonStyle") {
print("BorderlessButtonStyle點擊事件")
}.buttonStyle(BorderlessButtonStyle())
.border(Color.black, width: 1)
.background(Color.yellow)