Skip to content

Instantly share code, notes, and snippets.

@lalkrishna
Created September 21, 2020 07:13
Show Gist options
  • Save lalkrishna/318d580940746bbad21df66ddd0c9e09 to your computer and use it in GitHub Desktop.
Save lalkrishna/318d580940746bbad21df66ddd0c9e09 to your computer and use it in GitHub Desktop.
import UIKit
class SelfSizedTableView: UITableView {
var maxHeight: CGFloat = UIScreen.main.bounds.size.height
override func reloadData() {
super.reloadData()
self.invalidateIntrinsicContentSize()
self.layoutIfNeeded()
}
override var intrinsicContentSize: CGSize {
setNeedsLayout()
layoutIfNeeded()
let height = min(contentSize.height, maxHeight)
return CGSize(width: contentSize.width, height: height)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment