我如何在inputAccessoryView中的uiview上垂直添加uiview?

时间:2016-07-27 08:31:42

标签: swift uiview

我尝试在我当前的输入附件视图上方添加包含多个按钮的uiview。我当前的输入附件视图是一个不断增长的textField(如iOS标准文本消息应用程序)。

class ViewController: UIViewController {

let textInputBar = ALTextInputBar()

// The magic sauce
// This is how we attach the input bar to the keyboard
override var inputAccessoryView: UIView? {
    get {
        return textInputBar
    }
}

// Another ingredient in the magic sauce
override func canBecomeFirstResponder() -> Bool {
    return true
}
}

Example of what I'm trying to do, the app (Facebook Messenger) has a growing textfield or textinput, and in this case, an bar of buttons bellow.

My current view, as mentioned earlier.

1 个答案:

答案 0 :(得分:0)

  

试试这段代码

class ViewController: UIViewController {
@IBOutlet weak var myTextField: UITextField!
var textInputBar:UIView = ALTextInputBar()// if it is a uiview type

  override func viewDidLoad() {
    super.viewDidLoad()
    myTextField.inputAccessoryView = textInputBar
 }


}