How to disable iOS 8 emoji keyboard?

前端 未结 12 2180
说谎
说谎 2020-12-03 00:33

Is there any option to stop showing the emoji keyboard in iOS 8? It is not available in numpad and secure text but for email it is there. If it is not possible to disable i

12条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 01:19

    You can try this (Swift 5).

    Create String extension:

    extension String {
    
        func containsEmoji() -> Bool {
            for scalar in unicodeScalars {
                if !scalar.properties.isEmoji { continue }
                return true
            }
    
            return false
        }
    
    }
    

    Then use it in UITextFieldDelegate like this:

    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
         if string.containsEmoji() { return false }
         return true
    }
    

提交回复
热议问题