How to increase the UITableView separator height?

The best way for me, just add this in cellForRowAtIndexPath or in willDisplayCell

CGRect sizeRect = [UIScreen mainScreen].applicationFrame;    
NSInteger separatorHeight = 3;
UIView * additionalSeparator = [[UIView alloc] initWithFrame:CGRectMake(0,cell.frame.size.height-separatorHeight,sizeRect.size.width,separatorHeight)];
additionalSeparator.backgroundColor = [UIColor grayColor];
[cell addSubview:additionalSeparator];

For Swift 3.0:

let screenSize = UIScreen.main.bounds
let separatorHeight = CGFloat(3.0)
let additionalSeparator = UIView.init(frame: CGRect(x: 0, y: self.frame.size.height-separatorHeight, width: screenSize.width, height: separatorHeight))
additionalSeparator.backgroundColor = UIColor.gray
self.addSubview(additionalSeparator)

You should add this to cell's method awakeFromNib() to avoid re-creation.


I have seen many clunky solutions like subclassing UITableView with hidden cells, and other less optimal ones incl. in this thread.

When initializing the UITableView, Set the rowHeight property of UITableView to a height that equals = cell height + desired separator/space height.

Do not use standard UITableViewCell class though, instead, subclass the UITableViewCell class and override its layoutSubviews method. There, after calling super (don't forget that), set the height of the cell itself to desired height.

BONUS UPDATE 18/OCT/2015:

You can be a bit smart about this. The solution above basically puts the "separator" at the bottom of the cell. What really happens is, the row height is managed by the TableViewController but the cell is resized to be a bit lower. This results in the separator/empty space being at the bottom. But you can also centre all the subviews vertically so that you leave the same space at the top and the bottom. For example 1pt and 1pt.

You can also create isFirst, isLast convenience properties on your cell subclass. You would set these to yes in the cellForRowAtIndexPath. This way you can handle the edge cases for top and bottom separators inside the layoutSubviews method as this would have access to these properties. This way you can handle the edge cases for top or bottom - because sometimes the design department wants N+1 separators while the number of cells is only N. So you have to either deal with the top one or the boot one in a special way. But it's best do this inside cells instead tableViewHeader or TableViewFooter.


I don't think it's possible using standard API. I guess you would need to subclass the UITableViewCell and add a view that simulates a separator at the bottom of the cell.

You may want to check this question, it seems related and has some sample code: iPhone + UITableView + place an image for separator


In Swift

The easiest and shortest way for me was to add the snippet below in cellForRowAtIndexPath or in willDisplayCell:

override func tableView(tableView: UITableView,
                        willDisplayCell cell: UITableViewCell,
                        forRowAtIndexPath indexPath: NSIndexPath)
{
        let additionalSeparatorThickness = CGFloat(3)
        let additionalSeparator = UIView(frame: CGRectMake(0,
                                                           cell.frame.size.height - additionalSeparatorThickness,
                                                           cell.frame.size.width,
                                                           additionalSeparatorThickness))
        additionalSeparator.backgroundColor = UIColor.redColor()
        cell.addSubview(additionalSeparator)
}

You can do this entirely in the storyboard. Here is how:

  • go to the storyboard and select the tableview
  • Show the Size Inspector and from there set row height to say 140.
  • then show the Attributes Inspector and from there set your separator to Single Line and Style Plain and choose a color
  • then in the storyboard (or in Document Outline) select the cell
  • and again in the Size Inspector, under the Table View Cell, set custom Row Height to say 120.

That’s all. Your separator will be 20 units tall.