#11 瘋狂購物 App — UIStepper 和數字變字串練習

程式碼:

import UIKitclass shopTableViewController: UITableViewController {@IBOutlet weak var firstStepper: UIStepper!@IBOutlet weak var secondStepper: UIStepper!@IBOutlet weak var thirdStepper: UIStepper!@IBOutlet weak var fourthStepper: UIStepper!@IBOutlet weak var totalLabel: UILabel!@IBOutlet var quantityLabel: [UILabel]!var price1 = 0var price2 = 0var price3 = 0var price4 = 0@IBAction func pressed(_ sender: UIStepper) {switch sender {case self.firstStepper :self.firstStepper.minimumValue = 0self.firstStepper.maximumValue = 10000000000self.firstStepper.stepValue = 1self.price1 = Int(self.firstStepper.value)self.quantityLabel[0].text = “\(self.price1)”self.totalLabel.text = “\(String( self.price1 * 4800 + self.price2 * 8900 + self.price3 * 8900 + self.price4 * 7400 ))元”case self.secondStepper :self.secondStepper.minimumValue = 0self.secondStepper.maximumValue = 10000000000self.secondStepper.stepValue = 1self.price2 = Int(self.secondStepper.value)self.quantityLabel[1].text = “\(self.price2)”self.totalLabel.text = “\(String( self.price1 * 4800 + self.price2 * 8900 + self.price3 * 8900 + self.price4 * 7400 ))元”case self.thirdStepper :self.thirdStepper.minimumValue = 0self.thirdStepper.maximumValue = 10000000000self.thirdStepper.stepValue = 1self.price3 = Int(self.thirdStepper.value)self.quantityLabel[2].text = “\(self.price3)”self.totalLabel.text = “\(String( self.price1 * 4800 + self.price2 * 8900 + self.price3 * 8900 + self.price4 * 7400 ))元”case self.fourthStepper :self.fourthStepper.minimumValue = 0self.fourthStepper.maximumValue = 10000000000self.fourthStepper.stepValue = 1self.price4 = Int(self.fourthStepper.value)self.quantityLabel[3].text = “\(self.price4)”self.totalLabel.text = “\(String( self.price1 * 4800 + self.price2 * 8900 + self.price3 * 8900 + self.price4 * 7400 ))元”default :break}}

--

--