Use a custom .xib as a tableHeaderView

Oct 8 · 2 min read


Creating a custom TableView for your project can be a tricky thing sometimes.. Endless customization options are at your fingertips when it comes to Apple UI and its honestly very fun to work with! Today I will be explaining how to use a custom .xib file as a tableViewHeader .

Initialize your TableView

To initialize a table view declare the variable like so let yourTableView = UITableView() . Now we have a tableView to work with!

Create a .xib

Click File -> New -> File , then this window will appear. Select View then click next and name your .xib file!

Open the .xib file and customize

The .xib file you just created will have a preloaded view ready for you to work with.. In this case we want to delete that view and add our own UI element to the file. Click the + button on the top right corner and search for / add a tableViewCell in the .xib. Now its time to do what you want and customize the cell! I’ll leave the creativity part up to you! Now go make a beautiful header :)

Show me the code!

After your file is ready go set the header in your view controllers class file. First you need to instantiate the .xib file. This will get your .xib ready to go!

let yourTableViewHeader = (Bundle.main.loadNibNamed(“YourTableViewHeader”, owner: self, options: nil)![0] as? UIView)

After thats done, set the header yourTableViewHeader.tableHeaderView = yourTableViewHeader

Enjoy this tutorial on how to set a tableViewHeader the “old” way (pre SwiftUI) ! If this helped you please let us know!


Innovating without forgetting to be creative.


Written by


“When you don’t create things, you become defined by your tastes rather than ability. So create.” | Software Developer | Founder of The Rise Collection.


Innovating without forgetting to be creative.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade