【发布时间】:2021-07-25 10:36:29
【问题描述】:
我有一个想要使用按钮刷新的颜色列表。这就是我现在所拥有的。
var body: some View {
let happy = ["red","blue","purple","green"]
let randomHappy = happy.randomElement()!
ZStack {
Rectangle()
.foregroundColor(/*@START_MENU_TOKEN@*/.blue/*@END_MENU_TOKEN@*/)
.ignoresSafeArea()
VStack{
Text(randomHappy)
Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/, label: {
Text("Button")
.foregroundColor(.black)
})
}
}
}
}
我考虑过刷新整个页面,但我认为仅仅刷新随机元素的结果可能太过分了。有人知道如何解决这个问题吗?
【问题讨论】: