Last active
August 29, 2015 14:14
-
-
Save tmm/53feb0c52f76ba6d9f9d to your computer and use it in GitHub Desktop.
Dynamic Table View Cell Height in iOS 8 and Swift (snippet from http://www.raywenderlich.com/87975/dynamic-table-view-cell-height-ios-8-swift)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Option 1 - For portrait orientation only | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| tableView.rowHeight = UITableViewAutomaticDimension | |
| tableView.estimatedRowHeight = 160.0 | |
| } | |
| // Option 2 - For both portrait and landscape orientations | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| tableView.rowHeight = UITableViewAutomaticDimension | |
| } | |
| func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { | |
| if isLandscapeOrientation() { | |
| return hasImageAtIndexPath(indexPath) ? 140.0 : 120.0 | |
| } else { | |
| return hasImageAtIndexPath(indexPath) ? 235.0 : 155.0 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment