Resize UIImageView based on height of UITableViewCell content using auto-detect constraints

I have a UITableViewCell

xib with an image at the bottom: enter image description here

As shown below, it has the following components:

  • UILabel

    - dateLabel
  • UILabel

    - addressLabel
  • UILabel

    - criteriaLabel
  • UIImageView

    - separatorImageView

Since I want to increase the height of the cell based on the content in the labels, I added below constraints for each:

enter image description here

So the limitations of dateLabel are:

enter image description here

addressLabel:

enter image description here

critLabel constraints:

enter image description here

Without adding constraints for the separatorImageView

cells, they look like this:

enter image description here

i.e. cells change depending on the perfect content :)

Now the problem is if I add below constraints on separatorImageView

:

enter image description here

The cells start to appear like this:

enter image description here

Specify what constraints should be added to separatorImageView

so that it resizes to fit the cell height without affecting proper cell resizing.

+3


source to share


1 answer


This may not be the best answer, but for special cases I do this:

  • create a UIView called resizingVIEW, pin it on top, bottom, trailing, leading superview (contentView)

  • remove separatorImageView Lower spatial constraint

  • ctrl + click from separatorImageView to resizingVIEW, select equal height


(NOTE set the background color to resizingVIEW to clear the color / or hide it)

0


source







All Articles