Skip to content

Instantly share code, notes, and snippets.

@MainasuK
Last active July 20, 2016 02:29
Show Gist options
  • Save MainasuK/f8d00d1a7601a207dd1cd2458362ba0e to your computer and use it in GitHub Desktop.
Save MainasuK/f8d00d1a7601a207dd1cd2458362ba0e to your computer and use it in GitHub Desktop.
iOS Tips: Change table view cell row height
// If you use self-size cell with stack view or Auto Layout.
// Try this to change row height with animation
// Assume you set the content heightConstraint which group in your stack view
// Or other heightConstraint to make your cell self-size
func changeRowHeight(in tableView: UITableView, at indexPath: IndexPath, with height: CGFloat) {
tableView.beginUpdates()
// Change your cell heightConstraint height
// Should not call tableView.reloadData otherwise do animation by yourself
// For example:
let cell = tableView.cellForRow(at: indexPath) as! YourTableViewCell
cell.heightConstraint.constant = 100
tableView.endUpdates()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment