I'm beginning to try out SwiftUI. I want the Circle is randomly changing the color from red or green.
struct ContentView: View {
@State var colorCircle = [".red", ".green"]
var body: some View {
ZStack {
Circle()
.fill(Color.colorCircle.randomElement())
.frame(width: 100,
height: 100)
.position(x: 250,
y: 320)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Aucun commentaire:
Enregistrer un commentaire