【发布时间】:2019-10-26 23:33:30
【问题描述】:
我正在构建一个测验应用程序。一个问题; 3个答案。答案位于单独的按钮中。
我管理了单击时更改按钮的颜色。例如从灰色到绿色/红色。但点击后按钮变回灰色。
有没有办法在点击后保留更改的颜色,比如 HTML 中的超链接?
这是样式代码:
struct MyButtonStyle: ButtonStyle {
func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
.padding(20)
.foregroundColor(.white)
.background(configuration.isPressed ? Color.red : Color.gray)
.cornerRadius(10.0)
【问题讨论】: