How can I add a toolbar above the keyboard?

后端 未结 9 1328
孤街浪徒
孤街浪徒 2020-11-27 10:35

I have created a UIToolBar programmatically and added a UITextField on it. Now, I need that toolbar to be above the keyboard when I click in anothe

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 11:09

    You do not need to do this in code anymore.

    1. Just simply drag UIView to the top bar of current scene and customize it as you want.

    1. In code simply put IBOutlet for both: toolbarView and textView and make connections.

      @IBOutlet private var toolbarView: UIView!
      @IBOutlet private var textView: UITextView!
      
    2. In viewDidLoad setup your toolbarView as accessoryView of your UItextView.

      override func viewDidLoad() {
          super.viewDidLoad()
      
          textView.inputAccessoryView = toolbarView
      }
      

    The result is following:

提交回复
热议问题