我正在尝试使用 SwiftUI 在另一个按钮中插入一个按钮。但是,如果我按下该按钮,它也会对按下的外部按钮进行动画处理,即使它不运行操作闭包。有没有办法防止这种情况,也许使用自定义 ButtonStyle?
它看起来是这样的:
这是按下内部按钮时的样子:
这是我的代码:
var body: some View {
Button(action: {
print("outer button pressed")
}) {
HStack {
Text("Button")
Spacer()
Button(action: {
print("inner button pressed")
}) {
Circle()
.foregroundColor(Color.accentColor.opacity(0.2))
.frame(width: 28.0, height: 28.0)
.overlay(Image(systemName: "ellipsis"))
}
}
.padding()
.accentColor(.white)
.background(Color.accentColor)
.clipShape(RoundedRectangle(cornerRadius: 14.0, style: .continuous))
}
.frame(maxWidth: 200.0)
.padding()
}
Run Code Online (Sandbox Code Playgroud) 我想制作一个自定义 DisclosureGroup,它具有与默认 DisclosureGroup 相同的功能,但允许我更改颜色文本,甚至可以放置图像而不是字符串。
因为 DisclosureGroup 不允许我删除左侧的蓝色箭头指示符,并且它有限制。
目前默认的 DisclosureGroup 是:
struct ContentView: View {
@State private var revealDetails = false
var body: some View {
DisclosureGroup("Show Terms", isExpanded: $revealDetails) {
Text("Long terms and conditions here long terms and conditions here long terms and conditions here long terms and conditions here long terms and conditions here long terms and conditions here.")
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望能够做这样的事情:
struct ContentView: View {
@State private var isExpanded = false
var body: some View {
CustomDisclosureGroup(isExpanded: …Run Code Online (Sandbox Code Playgroud)