Last active
March 10, 2022 13:17
-
-
Save johneris/2263781090f271a7a647 to your computer and use it in GitHub Desktop.
Swift version of https://gist.github.com/booiiing/7941890
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 IntrinsicTableView: UITableView { | |
override var contentSize:CGSize { | |
didSet { | |
self.invalidateIntrinsicContentSize() | |
} | |
} | |
override func intrinsicContentSize() -> CGSize { | |
self.layoutIfNeeded() | |
return CGSize(width: UIViewNoIntrinsicMetric, height: self.contentSize.height) | |
} | |
override func endUpdates() { | |
super.endUpdates() | |
self.invalidateIntrinsicContentSize() | |
} | |
override func reloadData() { | |
super.reloadData() | |
self.invalidateIntrinsicContentSize() | |
} | |
override func reloadRowsAtIndexPaths(indexPaths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation) { | |
super.reloadRowsAtIndexPaths(indexPaths, withRowAnimation: animation) | |
self.invalidateIntrinsicContentSize() | |
} | |
override func reloadSections(sections: NSIndexSet, withRowAnimation animation: UITableViewRowAnimation) { | |
super.reloadSections(sections, withRowAnimation: animation) | |
self.invalidateIntrinsicContentSize() | |
} | |
override func insertRowsAtIndexPaths(indexPaths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation) { | |
super.insertRowsAtIndexPaths(indexPaths, withRowAnimation: animation) | |
self.invalidateIntrinsicContentSize() | |
} | |
override func insertSections(sections: NSIndexSet, withRowAnimation animation: UITableViewRowAnimation) { | |
super.insertSections(sections, withRowAnimation: animation) | |
self.invalidateIntrinsicContentSize() | |
} | |
override func deleteRowsAtIndexPaths(indexPaths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation) { | |
super.deleteRowsAtIndexPaths(indexPaths, withRowAnimation: animation) | |
self.invalidateIntrinsicContentSize() | |
} | |
override func deleteSections(sections: NSIndexSet, withRowAnimation animation: UITableViewRowAnimation) { | |
super.deleteSections(sections, withRowAnimation: animation) | |
self.invalidateIntrinsicContentSize() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated for swift4 https://gist.github.com/fabstu/2d8d78f67d24e71c9f59dbf8f5c3311d