我創建了自定義鍵盤,它工作正常。但我不知道如何將我的自定義鍵盤設置爲特定的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