【发布时间】:2021-12-27 17:10:08
【问题描述】:
我构建了一个自定义按钮。
我的问题是,它只能在文本元素上单击,而不能在按钮的整个区域上单击。
怎么回事,怎么解决?
struct MyButton: View {
var body: some View
{ Button( action:{ print("pressed") })
{ HStack {
VStack(alignment: .leading){
Text("Tomorrow").font(.caption)
Text("23.5.22 KW 23")
}
Spacer()
}
}
.padding([.horizontal],4.0)
.padding([.vertical],2.0)
.background(RoundedRectangle(cornerRadius: 5).fill(Color.red))
.buttonStyle(PlainButtonStyle())
.padding([.horizontal],8.0)
}
}
【问题讨论】:
-
将填充移动到 HStack,而不是按钮。