Create a xib file, you can also set it by dragging and dropping
Then instantiate it through code, and then add it to the view.
let bundle = Bundle(for: type(of: self))
UINib(nibName: "HeaderView", bundle: bundle).instantiate(withOwner: self, options: nil)
addSubview(view)
view.frame = bounds
I wrote it myself as a memo, please forgive me if it is not clear.