Last active
May 9, 2019 21:54
-
-
Save dev-yong/c5024119f321148174055b96a40d90ca to your computer and use it in GitHub Desktop.
This file contains 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
public class DynamicHeightTableView: UITableView { | |
public var maxHeight: CGFloat = UIScreen.main.bounds.height | |
override public var contentSize: CGSize { | |
didSet { | |
self.invalidateIntrinsicContentSize() | |
} | |
} | |
override public func reloadData() { | |
super.reloadData() | |
self.invalidateIntrinsicContentSize() | |
} | |
override public var intrinsicContentSize: CGSize { | |
super.layoutIfNeeded() | |
let height = min(contentSize.height, maxHeight) | |
return CGSize(width: contentSize.width, height: height) | |
} | |
} |
Author
dev-yong
commented
May 7, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment