Practicing swift making a tip calculator. I know using a number keyboard would make this a lot easier but I'm wanting this custom "keyboard" or number pad like a calculator app to be able to edit the text field "TotalBill". I know you can do this by updating a label with the button numbers being pressed but there is no user notification that something will happen if you start typing on the buttons.
I hope that all made sense. Thanks.
Updated:
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
}
}