Skip to content

Instantly share code, notes, and snippets.

@BrunoScheltzke
Created July 6, 2020 21:33
Show Gist options
  • Select an option

  • Save BrunoScheltzke/d39f655c859a42110e5ceaaf5182312e to your computer and use it in GitHub Desktop.

Select an option

Save BrunoScheltzke/d39f655c859a42110e5ceaaf5182312e to your computer and use it in GitHub Desktop.
Table and Collection view with intrinsic content size
//
// 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