有没有办法使列表的整行都不可点击?
我正在尝试使按钮行上只有按钮可点击。
如您所见,如果我尝试单击按钮行中的任何位置,无论是在按钮本身上,还是在其周围的空白处,它都会将其视为点击:
有没有办法让你只能点击按钮本身,而不是它周围的白色间距?(即行本身)
这是代码:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
List {
NavigationLink(destination: Text("Next screen")) {
Text("Item")
}
Button(action: {}) {
Text("Button")
}
.padding(.vertical, 12)
.frame(maxWidth: .infinity)
.background(Color(UIColor.secondarySystemBackground))
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
是的,在这个实现中,我绝对必须将这些元素放在 a 中List,所以我真的没有任何其他选择(例如通常使用 a VStack)
Asp*_*eri 10
使其成为非默认按钮样式,例如普通或您的自定义
Button(action: {}) {
Text("Button")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.contentShape(Rectangle())
}
.buttonStyle(PlainButtonStyle()) // << here !!
Run Code Online (Sandbox Code Playgroud)
另请参阅此帖子,例如使用自定义按钮样式执行类似操作
| 归档时间: |
|
| 查看次数: |
1835 次 |
| 最近记录: |