【问题标题】:How do I set Custom Keyboad as a default keyboard to UITextView?如何将自定义键盘设置为 UITextView 的默认键盘?
【发布时间】:2016-02-03 08:52:10
【问题描述】:

我已经创建了自定义键盘,它工作正常。但我不知道如何将我的自定义键盘设置为特定的 UITextField。 这是我的键盘视图控制器

import UIKit

class KeyboardViewController: UIInputViewController {

    @IBOutlet var nextKeyboardButton: UIButton!
    @IBOutlet weak var percentView: UIView!
    @IBOutlet weak var hideKeyboardButton: UIButton!

    override func updateViewConstraints() {
        super.updateViewConstraints()

        // Add custom view sizing constraints here
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Perform custom UI setup here
        self.nextKeyboardButton = UIButton(type: .System)

        self.nextKeyboardButton.setTitle(NSLocalizedString("Next Keyboard", comment: "Title for 'Next Keyboard' button"), forState: .Normal)
        self.nextKeyboardButton.sizeToFit()
        self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = false

        self.nextKeyboardButton.addTarget(self, action: "advanceToNextInputMode", forControlEvents: .TouchUpInside)

        self.view.addSubview(self.nextKeyboardButton)


        let nextKeyboardButtonLeftSideConstraint = NSLayoutConstraint(item: self.nextKeyboardButton, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1.0, constant: 0.0)
        let nextKeyboardButtonBottomConstraint = NSLayoutConstraint(item: self.nextKeyboardButton, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1.0, constant: 0.0)
        self.view.addConstraints([nextKeyboardButtonLeftSideConstraint, nextKeyboardButtonBottomConstraint])

        let nib = UINib(nibName: "KeyboardView", bundle: nil)
        let objects = nib.instantiateWithOwner(self, options: nil)
        view = objects[0] as! UIView;

        for view in self.view.subviews {
            if let btn = view as? UIButton {
                btn.layer.cornerRadius = 5.0
                btn.translatesAutoresizingMaskIntoConstraints = false
                //btn.addTarget(self, action: "keyPressed:", forControlEvents: .TouchUpInside)
            }
        }
    }

和其他委托方法。那我怎么称呼它呢? 实际上问题是我无法从应用扩展中导入自定义键盘类。这是主要问题。我做了这一切构建阶段的东西。如果我自己更换键盘,我可以使用键盘。

【问题讨论】:

  • 您是要在 UITextField 中添加自定义字体,还是只为特定文本字段使用该键盘?
  • 不。我创建了数字键盘作为 iPad 应用程序的自定义键盘。所以我需要将此键盘设置为一些特定的 UITextFileds 到默认键盘。
  • 您可能会在这里找到答案,customkeyboard

标签: swift uitextfield swift2 custom-keyboard


【解决方案1】:

根据Apple Documentation

用户选择自定义键盘后,它将成为用户打开的每个应用程序的键盘。

因此,它不像您的应用特定的东西,它更像是不同语言的键盘。至于你不能为你的 UITextField 或 UITextView 指定一些特定的语言键盘,你也不能指定你的自定义键盘。

您确定需要自定义键盘而不是自定义视图来在应用内输入数据吗?关于自定义数据输入视图,您可以阅读here

【讨论】:

  • 其实在 obj-c 中我也可以做到。但问题是我无法从应用扩展导入自定义键盘类。这是主要问题。
猜你喜欢
  • 2018-07-25
  • 1970-01-01
  • 2017-04-09
  • 2011-04-24
  • 1970-01-01
  • 2010-11-11
  • 1970-01-01
  • 2010-09-20
  • 1970-01-01
相关资源
最近更新 更多