【发布时间】:2020-07-04 09:04:36
【问题描述】:
我对 Swift 还很陌生,所以请多多包涵。
screenshot when nothing's tapped
screenshot when one button is tapped
我正在尝试转动其他按钮,这些按钮未被点击、处于非活动状态并将不透明度更改为 0.5。
到目前为止,我已经尝试过使用 $bindings,但这并没有按照我想要的方式工作。
这是我的 SelectionButtons 的代码:
struct SelectionButton: View {
var buttonText = "Selection Button"
var buttonColor = Color.white
var buttonWidth: CGFloat = 150
var active = false
var body: some View {
ZStack {
if active {
RoundedRectangle(cornerRadius: 45)
.frame(width: buttonWidth, height: 50)
.foregroundColor(Color("neonGreen"))
.shadow(color: Color(#colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.25)), radius:9, x:0, y:0)
Text(buttonText)
.font(.system(size: 18))
.foregroundColor(.black)
.bold()
}else{
RoundedRectangle(cornerRadius: 45)
.frame(width: buttonWidth, height: 50)
.foregroundColor(buttonColor)
.shadow(color: Color(#colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.25)), radius:9, x:0, y:0)
Text(buttonText)
.font(.system(size: 18))
.foregroundColor(.black)
}
}
}
这就是我使用它们的方式:
@State var gelbesBlatt = false
var body: some View {
NavigationView {
Button(action: {
self.gelbesBlatt.toggle()
}, label: {SelectionButton(buttonText: "gelb", buttonColor: .white, buttonWidth: 150, active: gelbesBlatt)
})
}
}
谢谢!
如果您知道我可以如何添加组合,以便可以一起选择属于一起的特定按钮(例如“Ganzes Blatt > gelb”和“Ränder > braun”),那就太棒了!
【问题讨论】:
标签: ios button binding swiftui