gpt4 book ai didi

SwiftUI - 列表中的两个按钮

转载 作者:搜寻专家 更新时间:2023-10-31 19:40:11 24 4
gpt4 key购买 nike

我在一个列表中有两个按钮,当点击时,列表项的整个区域都会突出显示。有没有办法把两个按钮分开?

在这种情况下,我有一个操作按钮和一个信息按钮:

enter image description here

我找到了 this question ,没有直接的解决方案。

代码如下:

var body: some View {
HStack {
Text(control.name)
Spacer()
Button(action: {
print("action")
}) {
Text("Action")
}
.frame(width: 250 - 10)
.padding(5)
.background(Color(white: 0.9))
.cornerRadius(10)
.frame(width: 250)
Group {
Button(action: {
print("action")
}) {
Image(systemName: "info.circle")
.foregroundColor(.accentColor)
}
}
}
}

最佳答案

将按钮样式设置为与默认样式不同的样式,例如 BorderlessButtonStyle()

struct Test: View {
var body: some View {
NavigationView {
List {
ForEach([
"Line 1",
"Line 2",
], id: \.self) {
item in
HStack {
Text("\(item)")
Spacer()
Button(action: { print("\(item) 1")}) {
Text("Button 1")
}
Button(action: { print("\(item) 2")}) {
Text("Button 2")
}
}
}
.onDelete { _ in }
.buttonStyle(BorderlessButtonStyle())
}
.navigationBarItems(trailing: EditButton())
}
.accentColor(.red)
}
}

关于SwiftUI - 列表中的两个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56576298/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com