Skip to content

Instantly share code, notes, and snippets.

@Adnan1990
Forked from db42/SelfSizedTableView.swift
Created August 16, 2021 12:47
Show Gist options
  • Save Adnan1990/c34502297e7cb1e6d1415aac5d4cdd94 to your computer and use it in GitHub Desktop.
Save Adnan1990/c34502297e7cb1e6d1415aac5d4cdd94 to your computer and use it in GitHub Desktop.
Swift 4 recipe: Self sizing table view
//
// SelfSizedTableView.swift
// AdjustableTableView
//
// Created by Dushyant Bansal on 25/02/18.
// Copyright © 2018 db42.in. All rights reserved.
//
import UIKit
class SelfSizedTableView: UITableView {
var maxHeight: CGFloat = UIScreen.main.bounds.size.height
override func reloadData() {
super.reloadData()
self.invalidateIntrinsicContentSize()
self.layoutIfNeeded()
}
override var intrinsicContentSize: CGSize {
let height = min(contentSize.height, maxHeight)
return CGSize(width: contentSize.width, height: height)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment