我想收集价格以标签打印总金额
@IBOutlet weak var typlabale: UILabel!
@IBOutlet weak var fruitLabel: UILabel!
@IBOutlet weak var typPrice: UILabel!
@IBOutlet weak var fruitPrice: UILabel!
@IBOutlet weak var totaleValue: UILabel!
var CupValue: Int = 8
var ConeValue: Int = 20
var StrawberryValue : Int = 20
var RaspberryValue : Int = 20
var BananaValue : Int = 10
// Mark : - Typ selec
@IBAction func typesegm(_ sender: Any) {
switch typesegm.selectedSegmentIndex
{
case 0:
typlabale.text = "Cup"
typPrice.text = "$\(CupValue)"
case 1:
typlabale.text = "Cone"
typPrice.text = "$\(ConeValue)"
default:
break;
}
}
// Fruit
@IBAction func fruitSegm(_ sender: Any) {
switch fruit.selectedSegmentIndex
{
case 0:
fruitLabel.text = "Strawberry"
fruitPrice.text = "$\(StrawberryValue)"
case 1:
fruitLabel.text = "Raspberry"
fruitPrice.text = "$\(RaspberryValue)"
case 2:
fruitLabel.text = "Banana"
fruitPrice.text = "$\(BananaValue)"
default:
break;
}
}
答案 0 :(得分:0)
添加此行
totaleValue.text = "$\(Int(typPrice.text!.replacingOccurrences(of: "$", with: ""))! + Int(fruitPrice.text!.replacingOccurrences(of: "$", with: ""))!)"
在此typesegm
和fruitSegm
方法的末尾。
@IBAction func typesegm(_ sender: Any) {
switch typesegm.selectedSegmentIndex
{ ... }
totaleValue.text = "$\(Int(typPrice.text!.replacingOccurrences(of: "$", with: ""))! + Int(fruitPrice.text!.replacingOccurrences(of: "$", with: ""))!)"
}
@IBAction func fruitSegm(_ sender: Any) {
switch fruit.selectedSegmentIndex
{ ... }
totaleValue.text = "$\(Int(typPrice.text!.replacingOccurrences(of: "$", with: ""))! + Int(fruitPrice.text!.replacingOccurrences(of: "$", with: ""))!)"
}