현재, 사용자가 키패드의 숫자를 클릭하면 한 단계에서 다음 단계로 textfields
이동하는 6 개가 textfield
있습니다.
내가 해결하려는 문제는 다음과 같습니다 . 사용자 Delete Button
가 다른 번호를 다시 입력하기 위해 돌아 가기 위해를 클릭하는 경우 프로그램에서 코드를 어떻게 작성합니까?
사용자가 다시 키패드에 새 번호를 입력 textfield
하고 원래 코드로 되돌 리도록하려면 어떻게해야합니까?
사용자가 키패드에 6 개 필드에 숫자 하나를 입력 한 다음을 클릭하여 Delete Button
돌아가서 번호를 다시 입력 할 수 있기를 바랍니다. 사용자가를 클릭해야합니다 Delete Button
.
또한에서 깜박이는 파란색 선을 제거하려면 어떻게해야 UItextfield
합니까?
나는 잠시 동안이 문제에 갇혀 있었고 이것을 해결하는 방법을 알 수 없습니다.
@objc func textFieldDidChange(textfield: UITextField) {
let text = textfield.text
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
}
}
else {
}
}
이것을 사용할 수 있습니다 :
func textFieldDidChange(textField: UITextField) {
let text = textField.text!
if text.utf16.count == 0 {
switch textField {
case textField2:
textField1.becomeFirstResponder()
case textField3:
textField2.becomeFirstResponder()
case textField4:
textField3.becomeFirstResponder()
case textField5:
textField4.becomeFirstResponder()
case textField6:
textField5.becomeFirstResponder()
default:
break
}
} else if text.utf16.count == 2 {
let indexStartOfText = text.index(text.startIndex, offsetBy: 1)
textField.text = String(text[..<indexStartOfText])
let tempStr = String(text[indexStartOfText])
switch textField {
case textField1:
textField1.backgroundColor = UIColor.black
textField1.textColor = .white
textField2.becomeFirstResponder()
textField2.backgroundColor = UIColor.black
textField2.textColor = .white
textField2.text = tempStr
case textField2:
textField3.becomeFirstResponder()
textField3.backgroundColor = UIColor.black
textField3.textColor = .white
textField3.text = tempStr
case textField3:
textField4.becomeFirstResponder()
textField4.backgroundColor = UIColor.black
textField4.textColor = .white
textField4.text = tempStr
case textField4:
textField5.becomeFirstResponder()
textField5.backgroundColor = UIColor.black
textField5.textColor = .white
textField5.text = tempStr
case textField5:
textField6.becomeFirstResponder()
textField6.backgroundColor = UIColor.black
textField6.textColor = .white
textField6.text = tempStr
case textField6:
textField6.resignFirstResponder()
default:
break
}
}
}
이 코드에서 당신의 한 편지에 초점을하지 않습니다 UITextFields
(가), 당신이이 편지에 초점을 대신 sender.text.count
당신이 다음의 두 번째 번호를 설정 2와 동일 UITextField
하고, 만약이 sender.text.count
우리에 있기 때문에 (사용자 삭제 무언가를 의미 제로로 동일 Editing Changed
이벤트 ) 커서를 뒤로 돌려야합니다.
그리고 if의 첫 번째 문에서 UI에 대해 원하는 모든 것을 수행하십시오.
약간 지저분하지만 작동합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다