📜  swift uitextfield 仅以编程方式数字键盘锁 - Swift 代码示例

📅  最后修改于: 2022-03-11 15:00:59.239000             🧑  作者: Mango

代码示例2
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        let bytes: [Unicode.UTF8.CodeUnit] = Array([0x7F, 0x08, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2E, 0x2D])
        let newString = String(bytes: bytes, encoding: String.Encoding.utf8)!
        if let x = string.rangeOfCharacter(from: NSCharacterSet.init(charactersIn: newString) /* decimalDigits */ /* init(charactersIn: stringa) */ as CharacterSet) {
                return true
             } else {
             return false
          }
       }