Created
July 6, 2020 21:33
-
-
Save BrunoScheltzke/d39f655c859a42110e5ceaaf5182312e to your computer and use it in GitHub Desktop.
Table and Collection view with intrinsic content size
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
| // | |
| // IntrisicCollections.swift | |
| // | |
| // Created by Bruno Scheltzke on 13/06/20. | |
| // Copyright © 2020 Bruno Scheltzke All rights reserved. | |
| // | |
| import UIKit | |
| final class IntrinsicTableView: UITableView { | |
| override var contentSize: CGSize { | |
| didSet { | |
| invalidateIntrinsicContentSize() | |
| } | |
| } | |
| override var intrinsicContentSize: CGSize { | |
| layoutIfNeeded() | |
| return CGSize(width: UIView.noIntrinsicMetric, height: contentSize.height) | |
| } | |
| override func reloadData() { | |
| super.reloadData() | |
| layoutIfNeeded() | |
| } | |
| } | |
| final class IntrinsicCollectionView: UICollectionView { | |
| override var contentSize: CGSize { | |
| didSet { | |
| invalidateIntrinsicContentSize() | |
| } | |
| } | |
| override var intrinsicContentSize: CGSize { | |
| layoutIfNeeded() | |
| return CGSize(width: UIView.noIntrinsicMetric, height: contentSize.height) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment