有内边距的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)