How to restrict UITextField to take only numbers in Swift?
问题 I want the user to only enter numeric values in a UITextField . On iPhone we can show the numeric keyboard, but on iPad the user can switch to any keyboard. Is there any way to restrict user to enter only numeric values in a UITextField ? 回答1: Here is my 2 Cents. (Tested on Swift 2 Only) func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { let aSet = NSCharacterSet(charactersInString:"0123456789").invertedSet let