【发布时间】:2015-12-18 03:12:07
【问题描述】:
我想要 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()
}
}
我有任何大于/等于 7 的免费值。 等于/小于 6 是黄色背景。 等于/小于 3 是红色背景。
我的问题在于应用程序只会使用绿色和黄色,而完全忽略了红色。如何激活红色?
【问题讨论】:
标签: ios iphone swift if-statement uilabel