I am trying to figure this out. When I use the code below, I am able to move from one text field to the next and click the "Backspace" button but ONLY when the text field has text in there.
My Question: How can I click the "Backspace" button when the text field is blank and move to the previous text field?
Second Question: How do I get rid of the blinking blue line on the UITextField
?
Below is the code that I have. Any help will be greatly appreciated!
@objc func textFieldDidChange(textfield: UITextField) {
let text = textfield.text!
if text.utf16.count == 0 {
switch textfield {
case textField2:
textField1.becomeFirstResponder()
textField1.backgroundColor = UIColor.black
case textField3:
textField2.becomeFirstResponder()
textField2.backgroundColor = UIColor.black
case textField4:
textField3.becomeFirstResponder()
textField3.backgroundColor = UIColor.black
case textField5:
textField4.becomeFirstResponder()
textField4.backgroundColor = UIColor.black
case textField6:
textField5.becomeFirstResponder()
textField5.backgroundColor = UIColor.black
textField6.resignFirstResponder()
textField6.backgroundColor = UIColor.black
default:
break
}
}
else if text.utf16.count == 1 {
switch textfield {
case textField1:
textField1.backgroundColor = UIColor.black
textField1.textColor = .white
textField2.becomeFirstResponder()
textField2.backgroundColor = UIColor.black
textField2.textColor = .white
case textField2:
textField3.becomeFirstResponder()
textField3.backgroundColor = UIColor.black
textField3.textColor = .white
case textField3:
textField4.becomeFirstResponder()
textField4.backgroundColor = UIColor.black
textField4.textColor = .white
case textField4:
textField5.becomeFirstResponder()
textField5.backgroundColor = UIColor.black
textField5.textColor = .white
case textField5:
textField6.becomeFirstResponder()
textField6.backgroundColor = UIColor.black
textField6.textColor = .white
case textField6:
textField6.resignFirstResponder()
default:
break
}
}
}
textField
when click on backspace iftextField
is empty, right ? – Fanciful