接近完美禁用iOS的emoji表情键盘
支持iOS搜狗输入法和自动关联表情(如输入hehe,出来的表情)
注意:Swift的textView.text != disable_emoji(textView.text)
在OC里面用 ![xxx isEqualString:bbb]
转帖保留(谢谢):http://www.cnblogs.com/Leetvin/p/4384141.html
@IBOutlet weak var tf: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
tf.addTarget(self, action: "textFieldDidChange:", forControlEvents: UIControlEvents.EditingChanged)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func textViewDidChange(textView: UITextView) {
var textTange = textView.selectedTextRange
if(textView.text != disable_emoji(textView.text))
{
textView.text = disable_emoji(textView.text)
}
textView.selectedTextRange = textTange
}
func textFieldDidChange(textField: UITextField) {
var textTange = textField.selectedTextRange
if(textField.text != disable_emoji(textField.text))
{
textField.text = disable_emoji(textField.text)
}
textField.selectedTextRange = textTange
}
func disable_emoji(text:String)->String
{
var regex = NSRegularExpression(pattern: "[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]", options: NSRegularExpressionOptions.CaseInsensitive, error: nil)
var modifiedString = regex!.stringByReplacingMatchesInString(text, options: NSMatchingOptions(), range: NSMakeRange(0, text.utf16Count), withTemplate: "")
return modifiedString
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。