gpt4 book ai didi

swift - 如何将自定义键盘设置为 UITextView 的默认键盘?

转载 作者:可可西里 更新时间:2023-11-01 01:37:58 25 4
gpt4 key购买 nike

我已经创建了自定义键盘并且它工作正常。但我不知道如何将我的自定义键盘设置为特定的 UITextField。这是我的 KeyboardViewController

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)
}
}
}

和其他委托(delegate)方法。那我怎么调用它呢?实际上问题是我无法从应用程序扩展中导入自定义键盘类。这是主要问题。我做了所有构建阶段的事情。如果我自己更换键盘,我可以使用键盘。

最佳答案

根据Apple Documentation

After a user chooses a custom keyboard, it becomes the keyboard for every app the user opens.

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

您确定在应用内输入数据时需要自定义键盘而不是自定义 View 吗?关于自定义数据输入 View 你可以阅读here .

关于swift - 如何将自定义键盘设置为 UITextView 的默认键盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33495122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com