自定义键盘输入文本字段swift

时间:2016-08-29 16:35:42

标签: uitextfield swift3 custom-keyboard

custom keyboard for tip calculator 练习快速制作小费计算器。我知道使用数字键盘可以使这更容易,但我想要这个自定义&键盘"或数字键盘像计算器应用程序,以便能够编辑文本字段" TotalBill"。我知道你可以通过按下按钮号来更新标签来做到这一点,但是如果你开始在按钮上打字,就没有用户通知会发生某些事情。

我希望一切都有道理。谢谢。

更新:

var userTyping = false
@IBOutlet weak var totalBill: UITextField!
@IBAction func numberDelete(_ sender: UIButton) {
    if let currentTitle = perPersonTotal.text{
    let updatedTitle = currentTitle.substring(to: (currentTitle.index(before: (currentTitle.endIndex))))
    perPersonTotal.text = updatedTitle
    }
}
@IBOutlet weak var perPersonTotal: UILabel!
@IBAction func touchDigit(_ sender: UIButton) {
    if let digit = sender.currentTitle {
        if userTyping {
            let currentDisplay = perPersonTotal.text!
            perPersonTotal.text = currentDisplay + digit
        } else {
            perPersonTotal.text = digit
        }
        userTyping = true
    }

}

0 个答案:

没有答案
相关问题