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.

Revisions

  1. tmm renamed this gist May 6, 2015. 1 changed file with 0 additions and 0 deletions.
  2. tmm renamed this gist Feb 3, 2015. 1 changed file with 0 additions and 0 deletions.
  3. tmm created this gist Feb 3, 2015.
    20 changes: 20 additions & 0 deletions Dynamic Table View Cell Height in Swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    // 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
    }
    }