I would like demonstrate it from scratch, so you can learn from this guide. First off all you should create a view, simply click Command+N button or choose File-New-File from the menu of Xcode. Choose a View template under User Interface section as shown below. Give it a name, in this case a Header (you can name it whatever you want).

And create a class to it, again click Command+N or from menu as I mentioned above. In this case choose a Cocoa Touch Class under Source section as shown below. And name it, as a HeaderView. Subclass of UIView

Open up your Header.xib
file from the Project Manage. Click your view, give it a size as a freeform, Top bar to none, and Bottom bar to none. Add a UIButton
to this view, I guess you know already, how to do it. And click this view, go to the Identity Inspector. And give it a class, in this a HeaderView.swift is our class.

Connect your button as shown below and we are done:

Now all of our focus in code, insert following line of code to the viewDidLoad()
.
override func viewDidLoad() {
super.viewDidLoad()
// Load the view using bundle.
// Make sure a nib name should be correct
// And cast it to the class, something like this
if let headerView = Bundle.main.loadNibNamed("Header", owner: self, options: nil)?.first as? HeaderView {
// Do some stuff, configuration of the view
headerView.frame = CGRect.init(x: 0, y: 0, width: self.view.frame.width, height: 44)
headerView.button.setTitle("Done", for: .normal)
headerView.button.addTarget(self, action: #selector(self.doneAction(sender:)), for: .touchUpInside)
// Add this view as an accessory to the text field or text view, in this case I have added this to the text field
self.textField.inputAccessoryView = headerView
}
}
Create a custom function to the done button:
@objc func doneAction(sender: UIButton) {
// Do something
// Resing your text field or text view
self.textField.resignFirstResponder()
}
Congrats! You're done. I hope it will help.