Created
September 21, 2020 07:13
-
-
Save lalkrishna/318d580940746bbad21df66ddd0c9e09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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