【问题标题】:Add a Clear button functionality in Custom Keyboard using Swift使用 Swift 在自定义键盘中添加清除按钮功能
【发布时间】:2016-10-25 14:38:33
【问题描述】:

我使用包含删除和清除按钮的自定义键盘。我可以使用此代码删除字母

let obj =  UIInputViewController()
(obj.textDocumentProxy as UIKeyInput).deleteBackward()

是否有任何关键字可用于清除文本字段中的整个文本。

注意:我找到了this 链接,但它不适合我的要求

【问题讨论】:

    标签: swift2 xcode7 uiinputviewcontroller


    【解决方案1】:

    没有可用于通过自定义键盘删除文本字段中的整个文本的关键字。

    清除光标位置前文本字段中UITextDocumentProxy对象可以访问的所有文本

    if let word:String = self.textDocumentProxy.documentContextBeforeInput     
    {
        for _: Int in 0 ..< word.characters.count {
            self.textDocumentProxy.deleteBackward()
        }
    }
    

    若要删除光标位置后的文字,必须将光标向前移动才能删除。

    【讨论】:

      猜你喜欢
      • 2010-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-09
      • 2012-05-19
      相关资源
      最近更新 更多