Skip to content

Instantly share code, notes, and snippets.

@sekny
Created January 11, 2024 07:49
Show Gist options
  • Save sekny/784249078fbe4636617fe73858111441 to your computer and use it in GitHub Desktop.
Save sekny/784249078fbe4636617fe73858111441 to your computer and use it in GitHub Desktop.
Table View for work with FittedSheets
import UIKit
class TableViewFittedContent: UITableView {
override var contentSize: CGSize {
didSet {
self.invalidateIntrinsicContentSize()
}
}
override var intrinsicContentSize: CGSize {
self.layoutSubviews()
return CGSize(width: UIView.noIntrinsicMetric, height: contentSize.height)
}
func setupTableView<T : UITableViewCell>(cell: T.Type, rowHeight: CGFloat = 30) {
self.register(
UINib(nibName: cell.className, bundle: nil),
forCellReuseIdentifier: cell.className
)
self.bounces = true
self.translatesAutoresizingMaskIntoConstraints = false
self.contentInsetAdjustmentBehavior = .never
self.showsVerticalScrollIndicator = false
self.showsHorizontalScrollIndicator = false
// self.isScrollEnabled = true
self.rowHeight = CGFloat(rowHeight)
self.separatorStyle = .none
self.backgroundColor = .clear
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment