• 接近完美禁用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 ]", options: NSRegularExpressionOptions.CaseInsensitive, error: nil)

            var modifiedString = regex!.stringByReplacingMatchesInString(text, options: NSMatchingOptions(), range: NSMakeRange(0, text.utf16Count), withTemplate: "")

            return modifiedString

        }

  • 相关阅读:
    POJ1094查分约束,判断关系是否唯一
    POJ1087DFS+匈牙利或者DINIC
    POJ1087DFS+匈牙利或者DINIC
    #Leetcode# 34. Find First and Last Position of Element in Sorted Array
    #Leetcode# 18. 4Sum
    #Leetcode# 16. 3Sum Closest
    #Leetcode# 15. 3Sum
    #Leetcode# 42. Trapping Rain Water
    #Leetcode# 63. Unique Paths II
    #Leetcode# 62. Unique Paths
  • 原文地址:https://www.cnblogs.com/Leetvin/p/4384141.html
Copyright © 2020-2023  润新知