Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize UITableViewCell height by showing and hiding components using auto layout

I have 4 components in my cell.

  1. UIView
  2. UITextView
  3. UIImageView
  4. Another UIView on top of the UIImageView
  5. UIView
  6. UIView

These content can be changed according the data that comes from the server(Sometimes it needs to hide the 3rd image view, sometimes 5th UIView). I'm using auto layout and with the auto layout what is the way to change height of the cell?

like image 352
codebot Avatar asked Dec 28 '25 05:12

codebot


1 Answers

You can achieve this easily by using UIStackView. Stack views are a powerful tool for quickly and easily designing your user interfaces. Their attributes allow a high degree of control over how they lay out their arranged views.

Here is link for tutorial - Tutorial

If you hide a view from stackview it conveniently disappears from the layout, but it's still a subview of the stack view. So you don't have to do anything special if you want to bring it back later on. And by using self sizing cells, cells will automatically expand or collapse based on stack view height.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!