Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Space Between Sections in UITableview

I need to reduce the space between two sections ofUITableView. I looked at this question but the solution doesn't allow for my custom header view because it combines the space of the footer and header.

Here is a picture of the UITableView. The black color is the UITableView background color.

tableview screenshot

like image 868
Joel Avatar asked May 21 '15 03:05

Joel


People also ask

How do you add a space between UITableView cells?

The way I achieve adding spacing between cells is to make numberOfSections = "Your array count" and make each section contains only one row. And then define headerView and its height. This works great.

Why is there extra padding at the top of my UITableView?

Short answer is that this extra padding is probably due to the table view header (not the section header), and that UITableView doesn't like to be assigned a header with a height of 0.0.

How do I remove spaces between cells in Swift?

You can remove this by setting a property on the table view: self. tableView.


2 Answers

Did you try override this function:

override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {     return .leastNormalMagnitude } 
like image 170
Icaro Avatar answered Sep 28 '22 09:09

Icaro


On iOS 15 you may want to reduce the sectionHeaderTopPadding

if #available(iOS 15.0, *) {     tableView.sectionHeaderTopPadding = 0 } 
like image 34
rockdaswift Avatar answered Sep 28 '22 09:09

rockdaswift