2

I have table view with image and labels. I want dynamic table cell height depends on both label text height and also image size. How can I achieve that?enter image description here

Currently I have given aspect ration to image view , but in output its taking same aspect ration and making image view's size fix. I want that whatever size of image will come, my image view should be made of that size. I have achieved that cell's dynamic height depend on label size but how to do same with image? The concept of this question : Using Auto Layout in UITableView for dynamic cell layouts & variable row heights is working for label not for image

Community
  • 1
  • 1
Pooja Shah
  • 977
  • 16
  • 45
  • 1
    possible duplicate of [Using Auto Layout in UITableView for dynamic cell layouts & variable row heights](http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights) – Dániel Nagy May 11 '15 at 08:16
  • @DánielNagy I have referred that and make my cell size dynamic according to label text but now I want that to resize according to image size, How can I do that for image? – Pooja Shah May 11 '15 at 08:41
  • you can get the image size, and add width and height constraints programmatically, then you can set both of them to the size of the image. – Dániel Nagy May 11 '15 at 08:57

1 Answers1

2

If you are supporting iOS8 and above the below two line of code would work.

self.tableView.estimatedRowHeight = 400 //Just give a maximum value
self.tableView.rowHeight = UITableViewAutomaticDimension // This will take automatically.
Amit89
  • 3,000
  • 1
  • 19
  • 27