jeudi 19 mars 2020

How to create like a multiple value Boolean in SwiftUI?

Let say I have a SwiftUI component and I want it to change color according to a parameter I choose like :

Component(colorValue: "1")
Component(colorValue: "2")
Component(colorValue: "3")

colorValue: 1 would change the color of my component to red, 2 to green, 3 to blue for example.

When I only had 2 colors in the beggining of my project I used a boolean in my component :

Rectangle().fill(Color(colorValue ? "red" : "blue"))

But now that I have multiple choice, how can I achieve the color change by checking the value of the colorValue String ?

Thanks in advance !

Aucun commentaire:

Enregistrer un commentaire