我有这个简单应用程序的按钮和标签。当我点击按钮时,它会突出显示我的按钮(您可以在附图中看到),那么我该如何禁用它?我错过了什么?
代码:
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))
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
您可以创建一个ButtonStyle
没有突出显示的自定义:
struct StaticButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
}
}
Run Code Online (Sandbox Code Playgroud)
Button(action: {
displayLabel += 1
}) {
Rectangle()
.foregroundColor(.blue)
.frame(width: geo.size.width, height: geo.size.height)
}
.buttonStyle(StaticButtonStyle())
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
180 次 |
最近记录: |