Iva*_*van 12 button ios swift swiftui
如何让内部Button执行其操作而不是始终执行外部操作?
struct Foo: View {
var body: some View {
Button(action: { print("alloha") }) {
HStack {
Button(action: { print("hello") }) {
Image(systemName: "circle.fill")
}
Text("world")
Spacer()
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
它可以工作,只需为内部按钮提供足够的空间,因此点击测试可以指定要激活的按钮,如下例所示。(使用 Xcode 11.4 / iOS 13.4 测试)
struct Foo: View {
var body: some View {
Button(action: { print("alloha") }) {
HStack {
Button(action: { print("hello") }) {
Image(systemName: "circle.fill").padding() // << more space !!
.border(Color.red) // << for testing
}
Text("world")
Spacer()
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5015 次 |
| 最近记录: |