【发布时间】:2021-01-28 01:25:49
【问题描述】:
我正在尝试编写一个允许某人拆分账单小费的应用程序。我遇到困难的部分是实现一个 UIStepper,它将获取“splitTotal”字段的值并将其除以步进器的值。代码:
@IBAction func updateTip(_ sender: Any) {
let tipPercentages = [0.15, 0.20, 0.25]
let bill = Double(billField.text!) ?? 0
let tip = bill * tipPercentages[tipController.selectedSegmentIndex]
let total = bill + tip
let split = total / stepper
tipLabel.text = "$\(tip)"
totalLabel.text = "$\(total)"
splitTotal.text = "$\(total)"
tipLabel.text = String(format: "$%.2f",tip)
totalLabel.text = String(format: "$%.2f",total)
splitTotal.text = String(format: "$%.2f",split)
【问题讨论】:
标签: ios swift iphone xcode uistepper