一尘不染

总是(强制)输入小写或大写字母-iOS Swift

swift

如何以快速语言强制某些文本字段键入小写或大写?


阅读 383

收藏
2020-07-07

共1个答案

一尘不染

您应该return false进入,if block因为您已经更新了textfield

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
  if textField.isEqual(textFieldBodrum) {
     textFieldBodrum.text = (textField.text as NSString).stringByReplacingCharactersInRange(range, withString: string.lowercaseString)
     return false
  } else if textField.isEqual(textFieldYalikavak) {
                textFieldYalikavak.text = (textField.text as NSString).stringByReplacingCharactersInRange(range, withString: string.uppercaseString)
    return false
  }
   return true
}

If you don’t want to affect other textfields you should return true end of
the shouldChangeCharactersInRange function.

https://gist.github.com/fatihyildizhan/ac5f476aebd306b0580a1fa069f153a3

2020-07-07