Skip to content

Instantly share code, notes, and snippets.

@BrentMifsud
Created November 3, 2021 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrentMifsud/ec5c91dbc02b7106fd0936e978ff0815 to your computer and use it in GitHub Desktop.
Save BrentMifsud/ec5c91dbc02b7106fd0936e978ff0815 to your computer and use it in GitHub Desktop.
UITableView that resizes to fit content
/// Resizes to fit its content. Or until size reaches provided constraints.
final class ContentResizingTableView: UITableView {
override var contentSize: CGSize {
didSet {
invalidateIntrinsicContentSize()
}
}
override var intrinsicContentSize: CGSize {
layoutIfNeeded()
return CGSize(width: UIView.noIntrinsicMetric, height: contentSize.height)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment