Support iOS Sogou Input method and auto-associated emoticons (such as input hehe, out of the expression)
Note: Swift's TextView. text ! = Disable_emoji(textView. Text)
Use in OC! [XXX isequalstring:bbb]
reprint reserved (thank you): http://www.cnblogs.com/Leetvin/p/4384141.html
@IBOutlet Weak var tf: uitextfield!
override func viewdidload () {
Super. Viewdidload()
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, 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
}
Close to perfect disable iOS emoji emoji keyboard