if(user.reserved == "yes") {
HStack {
Image(systemName: "person.crop.circle.badge.checkmark").foregroundColor(.green)
Text("\(user.name)").foregroundColor(.green)
}
} else if (user.reserved == "no"){
HStack {
Image(systemName: "person.crop.circle.badge.checkmark").foregroundColor(.red)
Text("\(user.name)").foregroundColor(.red)
}
} else if (user.reserved == "waiting") {
HStack {
Image(systemName: "person.crop.circle.badge.checkmark").foregroundColor(.orange)
Text("\(user.name)").foregroundColor(.orange)
}
}
'''
我有这个代码,我想根据用户说是或否来更改文本 colored颜色 的外观.我try 在if语句中创建一个类似"var color:color"的变量,但它一直说它不符合视图.我怎样才能有效地生成条件代码,而不是一次又一次地复制过go 的每一件事?