How to disable iOS 8 emoji keyboard?

前端 未结 12 2169
说谎
说谎 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

    For those who require international keyboards, this has worked well for iOS 9 and above:

    1. Add the following extension function to check if a string contains emoji:

      extension String {
          var containsEmoji: Bool {
          for scalar in unicodeScalars {
              switch scalar.value {
              case 0x3030, 0x00AE, 0x00A9,// Special Characters
              0x1D000...0x1F77F,          // Emoticons
              0x2100...0x27BF,            // Misc symbols and Dingbats
              0xFE00...0xFE0F,            // Variation Selectors
              0x1F900...0x1F9FF:          // Supplemental Symbols and Pictographs
                  return true
              default:
                  continue
              }
          }
          return false
         }
      }
      
    2. Another extension function to remove the emoji's from the string:

      extension String {
          var minusEmojis: String {
          let emojiRanges = [0x1F601...0x1F64F, 0x2702...0x27B0, 0x1D000...0x1F77F, 0x2100...0x27BF, 0xFE00...0xFE0F, 0x1F900...0x1F9FF]
          let emojiSet = Set(emojiRanges.joined())
          return String(self.filter { !emojiSet.contains($0.unicodeScalarCodePoint) })
         }
      }
      
    3. Add a target to your text field like this:

      textField.addTarget(self, action: #selector(didChangeText), for: .editingChanged)
      
    4. Finally remove any emoji present from the target selector:

      @objc func didChangeText(field: UITextField) {
           if (field.text?.containsEmoji == true) {
              field.text = field.text?.minusEmojis
          }
      }
      

    Hope this helps someone! Cheers.

提交回复
热议问题