Ios 如果有其他不允许颜色变化的情况?

Ios 如果有其他不允许颜色变化的情况?,ios,iphone,swift,if-statement,uilabel,Ios,Iphone,Swift,If Statement,Uilabel,我想要3个If/Else If语句,根据接收到的值改变背景颜色。到目前为止,我的代码是: /////Activity Response Selection///// @IBAction func ActivityAction(sender: AnyObject) { if(ActivitySeg.selectedSegmentIndex == 0) { ActivityVal.text = "Absent" ActivityNum.text = "0"

我想要3个If/Else If语句,根据接收到的值改变背景颜色。到目前为止,我的代码是:

/////Activity Response Selection/////
@IBAction func ActivityAction(sender: AnyObject) {

    if(ActivitySeg.selectedSegmentIndex == 0)
    {
    ActivityVal.text = "Absent"
    ActivityNum.text = "0"
    }
    else if(ActivitySeg.selectedSegmentIndex == 1)
    {
    ActivityVal.text = "Arms/Legs Flexed"
    ActivityNum.text = "1"
    }
    else if(ActivitySeg.selectedSegmentIndex == 2)
    {
    ActivityVal.text = "Active Movement"
    ActivityNum.text = "2"
    }


let ActivityIn = Double(ActivityNum.text!)
let PulseIn = Double(PulseNum.text!)
let GrimIn = Double(GrimNum.text!)
let AppIn = Double(AppNum.text!)
let RespIn = Double(RespNum.text!)

let product = ActivityIn! + PulseIn! + GrimIn! + AppIn! + RespIn!

TotalVal.text = "\(product)"
TotalVal.text = NSString(format: "APGAR Score: %2.0f", product)as String


if product >= 7.0 {
    TotalVal.backgroundColor = UIColor.greenColor()
}
else if product <= 6.0{
    TotalVal.backgroundColor = UIColor.yellowColor()
}
else if product <= 3.0 {
    TotalVal.backgroundColor = UIColor.redColor()
}
//活动响应选择/////
@iAction func ActivityAction(发件人:AnyObject){
如果(ActivitySeg.selectedSegmentIndex==0)
{
ActivityVal.text=“缺席”
ActivityNum.text=“0”
}
else if(ActivitySeg.selectedSegmentIndex==1)
{
ActivityVal.text=“手臂/腿部弯曲”
ActivityNum.text=“1”
}
else if(ActivitySeg.selectedSegmentIndex==2)
{
ActivityVal.text=“活动移动”
ActivityNum.text=“2”
}
让ActivityIn=Double(ActivityNum.text!)
让PulseIn=Double(PulseNum.text!)
让GrimIn=Double(GrimNum.text!)
让AppIn=Double(AppNum.text!)
让RespIn=Double(RespNum.text!)
让product=ActivityIn!+PulseIn!+GrimIn!+AppIn!+RespIn!
TotalVal.text=“\(产品)”
TotalVal.text=NSString(格式:“APGAR分数:%2.0f”,产品)作为字符串
如果产品>=7.0{
TotalVal.backgroundColor=UIColor.greenColor()
}

else-if-product问题是您最后的else-if语句


你的red(问题是你最后的else if语句


你的红色(有道理。谢谢!有道理。谢谢!
if product >= 7.0 {
    TotalVal.backgroundColor = UIColor.greenColor()
} else if product > 3.0 {
    TotalVal.backgroundColor = UIColor.yellowColor()
} else {
    TotalVal.backgroundColor = UIColor.redColor()
}