Space UITableViewCells in a UITableView

Put gaps between!

Steven Curtis
5 min readMay 30


Photo by Alex Radelich on Unsplash

Before we start

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 12.2, and Swift 5.3


This article is based on the [UITableView Programmatic Example](), and builds on that (although the code is given in this article

I usually remove the storyboard using this technique

Keywords and Terminology

Row: The content in a UITableview is ordered into rows

Section: A grouping of rows in a UITableView

UITableView: A view that presents data using rows arranged in a single column

UITableViewCell: The visual representation of a single row in a table view

This project


Before we look at how to put spaces in between UITableViewCells, let us look at some of the background of UITableView.

When we use a UITableView the view is made up of UITableViewCells

and the UITableView gets the information to be displayed from a datasource and delegate

However, we might want to add some sections — that is we will set up a header that can be displayed before some number of rows in a section. The following diagram shows Section A and Section B:

So how might this be set up?

The simplified project

This project will display some data in the UITableView, which is made up of an Array of names.