IQKeyboardToolbarManager

CI Status Version License Platform

Screenshot

示例

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install

要求

安装

IQKeyboardToolbarManager 可通过 CocoaPods 获得。 要安装它,只需将以下行添加到您的 Podfile 中

pod 'IQKeyboardToolbarManager'

用法

在 AppDelegate 中启用工具栏处理

import UIKit
import IQKeyboardToolbarManager

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        IQKeyboardToolbarManager.shared.isEnabled = true
        return true
    }

自定义行为

        IQKeyboardToolbarManager.shared.toolbarConfiguration.useTextInputViewTintColor = true
        IQKeyboardToolbarManager.shared.toolbarConfiguration.tintColor = UIColor.systemGreen
        IQKeyboardToolbarManager.shared.toolbarConfiguration.barTintColor = UIColor.systemYellow
        IQKeyboardToolbarManager.shared.toolbarConfiguration.previousNextDisplayMode = .alwaysShow
        IQKeyboardToolbarManager.shared.toolbarConfiguration.manageBehavior = .byPosition

        IQKeyboardToolbarManager.shared.toolbarConfiguration.previousBarButtonConfiguration = ... // BarButton configuration to change title, image or system image etc
        IQKeyboardToolbarManager.shared.toolbarConfiguration.nextBarButtonConfiguration = ... // BarButton configuration to change title, image or system image etc
        IQKeyboardToolbarManager.shared.toolbarConfiguration.doneBarButtonConfiguration = ... // BarButton configuration to change title, image or system image etc

        IQKeyboardToolbarManager.shared.toolbarConfiguration.placeholderConfiguration.showPlaceholder = false
        IQKeyboardToolbarManager.shared.toolbarConfiguration.placeholderConfiguration.font = UIFont.italicSystemFont(ofSize: 14)
        IQKeyboardToolbarManager.shared.toolbarConfiguration.placeholderConfiguration.color = UIColor.systemPurple
        IQKeyboardToolbarManager.shared.toolbarConfiguration.placeholderConfiguration.buttonColor = UIColor.systemBrown // This is used only if placeholder is an action button

        IQKeyboardToolbarManager.shared.playInputClicks = false

        IQKeyboardToolbarManager.shared.disabledToolbarClasses.append(ChatViewController.self)
        IQKeyboardToolbarManager.shared.enabledToolbarClasses.append(LoginViewController.self)
        IQKeyboardToolbarManager.shared.deepResponderAllowedContainerClasses.append(UIStackView.self)

有用的函数和变量

        if IQKeyboardToolbarManager.shared.canGoPrevious {
          ...
        }

        if IQKeyboardToolbarManager.shared.canGoNext {
          ...
        }

        IQKeyboardToolbarManager.shared.goPrevious()
        IQKeyboardToolbarManager.shared.goNext()

        IQKeyboardToolbarManager.shared.reloadInputViews() // If some textInputView hierarchy are changed on the fly then use this to reload button states

TextInputView 的有用函数和变量

        textField.iq.ignoreSwitchingByNextPrevious = false

作者

Iftekhar Qurashi hack.iftekhar@gmail.com

许可证

IQKeyboardToolbarManager 在 MIT 许可证下可用。 有关更多信息,请参见 LICENSE 文件。