Created
March 2, 2018 02:24
-
-
Save db42/72ad87c8a165e57f0db675a9fd3e5942 to your computer and use it in GitHub Desktop.
Swift 4 recipe: Self sizing table view
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
// | |
// 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