如果用户在 iOS Swift 3 中输入小写文本字段将其转换为大写,我想允许 CollectionViewCell 文本字段的所有字符(仅 alphabates)为大写且字符限制为 1?
最佳答案
在 Swift 3、4 中:
首先添加这行代码。它会大写你的键盘。
yourTextField.autocapitalizationType = .allCharacters
然后像那样将委托(delegate)设置为您想要的文本字段
yourTextField.delegate = self
现在实现这个文本框的委托(delegate)方法。这个方法听你的按键。
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
// check your char limit here & capitalized char based on your requirement.
yourTextField.text = textField.text?.uppercased()
return true
}
希望对您有所帮助。
关于ios - 如何在 iOS Swift 3 中允许 CollectionViewCell 文本字段的所有字符均为大写字母且字符限制为 1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48166267/