UITextfield keyboard with only alphabet, no numbers, no caps, no spacebar?

前端 未结 8 2146
深忆病人
深忆病人 2021-02-06 06:33

I want the keyboard for the UITextfield to only have a-z, no numbers, no special characters (!@$!@$@!#), and no caps. Basicly I am going for a keyboard with only the alphabet.

8条回答
  •  忘掉有多难
    2021-02-06 07:09

    Swift 3 solution

    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    
         let characterSet = CharacterSet.letters
    
         if string.rangeOfCharacter(from: characterSet.inverted) != nil {
             return false      
         }
         return true
    }
    

提交回复
热议问题