Skip to content

Instantly share code, notes, and snippets.

@tmm
Last active August 29, 2015 14:14
Show Gist options
  • Save tmm/53feb0c52f76ba6d9f9d to your computer and use it in GitHub Desktop.
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)
// 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