0

Is it possible to make a dynamic cell height programmatically and only using a frames? Without constraints, autolayout and external libraries!

In this custom tableView cell, i set frame for label with calculating height for text label:

override func layoutSubviews() {
    super.layoutSubviews()
    makeLayout()
}

func makeLayout() {
    let sizeLabel = descriptionLabel.sizeThatFits(bounds.size)
    descriptionLabel.frame = CGRect(x: 0, y: 0, width: bounds.width, height: sizeLabel.height)
}

I have view controller with tableView, where i implement his delegate with return automaticDimension, but it doesn't work

Dimbeard
  • 11
  • 3
  • Does this answer your question? [CollectionView Dynamic cell height swift](https://stackoverflow.com/questions/27285258/collectionview-dynamic-cell-height-swift) – Harry J Feb 15 '20 at 23:37
  • no, i set frame a label in custom cell, and implement tableView delegate – Dimbeard Feb 16 '20 at 08:14

1 Answers1

0

Yes, You will have to return the height programmatically by implementing the UITableViewDelegate function

Alfa
  • 599
  • 6
  • 22
  • yeah, but I have a custom cell with a label and set this label with a frame – Dimbeard Feb 15 '20 at 19:01
  • 1
    Calculate the frame of the UILabel and return the height along with whatever padding you might need. https://stackoverflow.com/questions/19128797/calculating-uilabel-text-size – Alfa Feb 15 '20 at 19:06