码迷,mamicode.com
首页 > 移动开发 > 详细

接近完美禁用iOS的emoji表情键盘

时间:2015-04-01 17:23:58      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

支持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

    }

接近完美禁用iOS的emoji表情键盘

标签:

原文地址:http://www.cnblogs.com/Leetvin/p/4384141.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!