【问题标题】:Check character in documentContextBeforeInput in Custom keyboard检查自定义键盘中 documentContextBeforeInput 中的字符
【发布时间】:2017-07-20 12:11:55
【问题描述】:
      ///Here is my Function  for Button press  


      @IBAction func keyPressed(_ button: UIButton) {
      var buttonTap = button.titleLabel!.text

       ///Here i call a variable for Get before input in textDocumentProxy  

     var   jukto = textDocumentProxy.documentContextBeforeInput 


      /// Now i want check if Three digits of documentContextBeforeInput is "ABC" Than it should change to "DE"

            if jukto == "ABC" {

              buttonTap  = "DE"

            }

     (textDocumentProxy as UIKeyInput).insertText("\(buttonTap!)")


    }

/// 注意:我的documentContext中会有很多字符,但我想检查“ABC”这3位数字是否在一起而不是改变。

【问题讨论】:

    标签: ios iphone swift swift2 custom-keyboard


    【解决方案1】:
      @IBAction func keyPressed(_ button: UIButton) {
      var buttonTap = button.titleLabel!.text
    
       ///Here i call a variable for Get before input in textDocumentProxy  
    
     var   jukto = textDocumentProxy.documentContextBeforeInput 
    
    
      /// Now i want check if Three digits of documentContextBeforeInputis "ABC" Than it should change to "DE"
    
    
           if jukto.range(of:"ABC") != nil{ 
              buttonTap  = "DE"
            }
    
            (textDocumentProxy as UIKeyInput).insertText("\(buttonTap!)")
    
    
    }
    

    【讨论】:

    • 如果文本字段中有单个字符,则它不起作用。就像,我需要检查 uitextfield 中是否有字母字符我需要在输入视图中插入“。”但是当文本字段中插入一个字符时,此代码不起作用
    猜你喜欢
    • 2015-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    • 2019-05-26
    • 2014-11-24
    • 2015-11-18
    • 1970-01-01
    相关资源
    最近更新 更多