1

我正在使用 IQKeyboardManager 并为完成按钮添加了自定义操作

txtfield.addDoneOnKeyboard(withTarget: self, action: #selector(doneButtonClicked), titleText: "Next")

IQKeyboardManager.shared().toolbarDoneBarButtonItemText = "Next"

@objc func doneButtonClicked(_ sender: Any) {
    //  do stuff
}

在这里,动作被调用,一切正常。但是完成按钮的标题是 DONE(蓝色)。

“下一个”作为标题文本显示在键盘中间。如何更改完成按钮的文本/颜色?如果我不向任何特定文本字段添加任何操作,则第二行可以完美运行,但无论何时添加操作,完成按钮的自定义名称都会被忽略。

有什么帮助吗?

github中的IQKeyboardManager

4

2 回答 2

2

使用以下内容:

 let config = IQBarButtonItemConfiguration(title: "Next", action: #selector(doneButtonClicked))
txtfield.addKeyboardToolbar(withTarget: self, titleText: nil , rightBarButtonConfiguration: config, previousBarButtonConfiguration: nil, nextBarButtonConfiguration: nil)

//  any color you like
txtfield.keyboardToolbar.doneBarButton.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.red], for: UIControl.State.normal)

代替:

txtfield.addDoneOnKeyboard(withTarget: self, action: #selector(doneButtonClicked), titleText: "Next")

更?titleTexttoolbar.titleBarButton.title

IQKeyboardManager我从这里的源代码中挑选了一些代码片段:

      //Title button
     toolbar.titleBarButton.title = titleText

toolbarDoneBarButtonItemText设置的doneBarButton.title

一些代码片段来自IQKeyboardManager这里:

    if let rightConfig = rightBarButtonConfiguration {

        var done = toolbar.doneBarButton

        if rightConfig.barButtonSystemItem == nil && done.isSystemItem == false {
             done.title = rightConfig.title
             done.image = rightConfig.image
             done.target = target
             done.action = rightConfig.action
        }

于 2019-06-20T06:26:55.867 回答
0

试试这个。

  1. 导入 IQKeyboardManagerSwift
  2. IQKeyboardManager.shared.toolbarDoneBarButtonItemText = "NEXT"

见下图在 Xcode 10.1 中有 NEXT 按钮。

在此处输入图像描述

于 2019-06-20T06:26:10.877 回答