Resize UIImageView based on height of UITableViewCell content using auto-detect constraints
I have a UITableViewCell
xib with an image at the bottom:
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:
So the limitations of dateLabel are:
addressLabel:
critLabel constraints:
Without adding constraints for the separatorImageView
cells, they look like this:
i.e. cells change depending on the perfect content :)
Now the problem is if I add below constraints on separatorImageView
:
The cells start to appear like this:
Specify what constraints should be added to separatorImageView
so that it resizes to fit the cell height without affecting proper cell resizing.
source to share
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)
source to share