iosuitableviewuiscrollviewframecontentsize

What is the difference between 'tableView.contentSize' and 'tableView.frame.size'


tableView.setContentOffset(CGPointMake(0, tableView.contentSize.height - tableView.frame.size.height), animated: true)

It works, but I wonder what actually are those two values: tableView.contentSize, tableView.frame.size


Solution

  • The contentSize is the size of the content of the UIScrollView, that means it will be the size of the content (hidden and visible) whereas the frame.size is the real size of your tableView.

    For example, let's say I have a device's screen of 568 (height), and inside it, I have an UITableView (taking all the screen) with 100 cells and an height of 50 for each of them. My tableView.frame.size.height will be equal to 568, but the tableView.contentSize.height will be equal of the scroll's size of all the cells, so 5000.

    Also, as suggested by @Ethaan, read this to go deeper.