Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add space below last element of Table view in swift

I need to add some extra space after the last element in the table view cell.

In android reccycler view, the same thing can be achieved by

android:paddingBottom="8dp"
 android:clipToPadding="false"

Table view last item

like image 509
Ebin Joy Avatar asked Mar 01 '19 05:03

Ebin Joy


People also ask

How do I add a space between tables in Swift?

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.

What is the use of tableview in swift?

Overview. Table views in iOS display rows of vertically scrolling content in a single column. Each row in the table contains one piece of your app's content. For example, the Contacts app displays the name of each contact in a separate row, and the main page of the Settings app displays the available groups of settings ...

What is UITableView in Swift?

UITableViews are one of the most commonly used views in iOS programming. They are used to display grouped lists of cells. Here are some examples of UITableViews : UITableViews can be highly performant, displaying thousands of rows of data.


2 Answers

You need to add insets to your tableView . Try the following code

let insets = UIEdgeInsets(top: 0, left: 0, bottom: 50, right: 0)
tableView.contentInset = insets
like image 177
Shubham Bakshi Avatar answered Nov 15 '22 05:11

Shubham Bakshi


Add datasource and delegate for your tableview and utilize following delegate methods: - heightForFooterInSection & viewForFooterInSection

// set view for footer
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    let footerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 40)) // assuming 40 height for footer.
    footerView.backgroundColor = <Some Color>
    return footerView
}

// set height for footer
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 40
}
like image 39
Rizwan Avatar answered Nov 15 '22 06:11

Rizwan