-
-
Save fabstu/2d8d78f67d24e71c9f59dbf8f5c3311d to your computer and use it in GitHub Desktop.
Swift version of https://gist.github.com/booiiing/7941890
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
import UIKit | |
class IntrinsicTableView: UITableView { | |
override var contentSize:CGSize { | |
didSet { | |
self.invalidateIntrinsicContentSize() | |
} | |
} | |
override var 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 reloadRows(at indexPaths: [IndexPath], with animation: UITableViewRowAnimation) { | |
super.reloadRows(at: indexPaths, with: animation) | |
self.invalidateIntrinsicContentSize() | |
} | |
override func reloadSections(_ sections: IndexSet, with animation: UITableViewRowAnimation) { | |
super.reloadSections(sections, with: animation) | |
self.invalidateIntrinsicContentSize() | |
} | |
override func insertRows(at indexPaths: [IndexPath], with animation: UITableViewRowAnimation) { | |
super.insertRows(at: indexPaths, with: animation) | |
self.invalidateIntrinsicContentSize() | |
} | |
override func insertSections(_ sections: IndexSet, with animation: UITableViewRowAnimation) { | |
super.insertSections(sections, with: animation) | |
self.invalidateIntrinsicContentSize() | |
} | |
override func deleteRows(at indexPaths: [IndexPath], with animation: UITableViewRowAnimation) { | |
super.deleteRows(at: indexPaths, with: animation) | |
self.invalidateIntrinsicContentSize() | |
} | |
override func deleteSections(_ sections: IndexSet, with animation: UITableViewRowAnimation) { | |
super.deleteSections(sections, with: animation) | |
self.invalidateIntrinsicContentSize() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
swift4