AutoSizeTableView 1.1.0

AutoSizeTableView 1.1.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jun 2016
SPMSupports SPM

Maintained by Daniel Saidi.



AutoSizeTableView

AutoSizeTableView is an iOS Swift library that can resize table view cells to fit their content.

How to use AutoSizeTableView

Using AutoSizeTableView is actually really easy, since it bases its functionality on auto layout. To use it, follow these simple steps:

  • Either inherit AutoSizeTableViewController or make your table view controller impement two delegate methods:

  • estimatedHeightForRowAtIndexPath - should return a value that represents an estimated cell height. The more accurate the better (but I would not sweat it).

  • heightForRowAtIndexPath - must only return the iOS value UITableViewAutomaticDimension.

As soon as you have this set up, you have to make sure to setup all table view cells properly.

  • For all labels that should autosize, set the number of lines to 0 and line breaks mode to word wrap. Do this for all custom and standard table view cells!

  • If you are using custom table view cells, make sure to setup auto layout properly, so that they actually resize to fit their content and that the container resizes with its content.

Make sure to call tableView.autoSizeContent(), whenever your data changes.

Current issues

For now, subtitle cells does not seem to handle auto size well. Until that issue is solved, use custom cells with a nice auto layout setup.

Demo

The demo project in this repository shows you how you can use the classes to auto size standard table view cells.

CocoaPod

You can easily add this library to your own project using CocoaPods (check out https://cocoapods.org). Just add the following to your pod file:

pod 'AutoSizeTableView', '<version>'

Contact

To get in touch with me regarding this and other projects that I am working on:

Project site:   http://github.com/danielsaidi/AutoSizeTableView
CocoaPod:       https://cocoapods.org/pods/AutoSizeTableView
Blog:           http://danielsaidi.wordpress.com
Twitter:        http://twitter.com/danielsaidi

Contributions to this project are more than welcome. Just send me a pull request or get in touch.