2015-11-03 29 views
2

我创建了自定义键盘,它工作正常。但我不知道如何将我的自定义键盘设置为特定的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) 
      } 
     } 
    } 

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

+0

您是否想要将自定义字体添加到UITextField中,或者只是将该键盘用于特定文本字段? –

+0

不是。我已创建数字键盘作为iPad应用程序的自定义键盘。所以我需要将此键盘设置为默认键盘的某些特定UITextFiled。 – letitbefornow

+0

您可能会在这里找到您的答案,[customkeyboard](http://stackoverflow.com/questions/33474771/a-swift-example-of-custom-views-for-data-input-custom-in-app-keyboard) – MBTDesigns

回答

2

根据Apple Documentation

当用户选择一个自定义键盘,它变成了键盘用户打开的所有应用。

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

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

+0

你可以用代码来证明它吗? – letitbefornow

+0

当然,我编辑了这个问题。 – letitbefornow

+0

其实在obj-c我也可以做到这一点。但问题是我无法从应用程序扩展中导入自定义键盘类。这是主要问题。 – letitbefornow

相关问题