【发布时间】:2019-09-05 04:36:19
【问题描述】:
我正在尝试在 SwiftUI 中更改我的 Button 的颜色。
这是我的整个 CustomButton 视图结构:
struct CustomButton: View {
@State private var didTap:Bool = false
var body: some View {
Button(action: {
self.didTap = true
}) {
Text("My custom button")
.font(.system(size: 24))
}
.frame(width: 300, height: 75, alignment: .center)
.padding(.all, 20)
.background(Color.yellow)
//My code above this comment works fine
//I tried something like this, but it is not working
// if didTap == true {
// .background(Color.blue)
// }
}
}
这就是我的按钮的样子(很好):
但我的问题是:如何在用户点击此按钮时更改背景颜色。
谢谢。
【问题讨论】:
标签: swift xcode swiftui xcode11