我创建了自定义键盘,它工作正常。但我不知道如何将我的自定义键盘设置为特定的UITextField。 这是我的KeyboardViewController如何将Custom Keybo作为默认键盘设置为UITextView?
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应用程序的自定义键盘。所以我需要将此键盘设置为默认键盘的某些特定UITextFiled。 – letitbefornow
您可能会在这里找到您的答案,[customkeyboard](http://stackoverflow.com/questions/33474771/a-swift-example-of-custom-views-for-data-input-custom-in-app-keyboard) – MBTDesigns