gpt4 book ai didi

swiftui - 如何使用 SwiftUI 删除按钮的高亮显示?

转载 作者:行者123 更新时间:2023-12-04 12:35:56 32 4
gpt4 key购买 nike

我有这个简单应用程序的按钮和标签。当我点击按钮时,它会突出显示我的按钮(您可以在附图中看到),那么我该如何禁用它?我错过了什么?
代码:

struct ContentView: View {
@State private var displayLabel = 0
var body: some View {
GeometryReader{ geo in
ZStack{
Button(action: {
displayLabel += 1
}, label: {
Rectangle()
.foregroundColor(.blue)
.frame(width: geo.size.width, height: geo.size.height)
}).buttonStyle(PlainButtonStyle())

Text("\(displayLabel)")
.font(Font.system(size:75, design: .rounded))
}
}
}
}
enter image description here

最佳答案

您可以创建自定义 ButtonStyle没有突出显示:

struct StaticButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
}
}
Button(action: {
displayLabel += 1
}) {
Rectangle()
.foregroundColor(.blue)
.frame(width: geo.size.width, height: geo.size.height)
}
.buttonStyle(StaticButtonStyle())

关于swiftui - 如何使用 SwiftUI 删除按钮的高亮显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64976412/

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