0
votes

I have a UILabel next to a UIImage where I want the UILabel to be show truncated "..." if it starts to overlap with the neighboring UIImage.

Text is behind the UIImage when i want it to just truncate:

text is behind the image

My UILabel properties: ui label properties

My image properties: image properties

I thought the issue is the content compression but I set the UILabel's content compression resistant priority horizontal to 250 and the UIImage to 1000. This only hides the UILabel behind the UIImage.

*This is inside a table cell. I'm not using the default table cell view because i intend to customize it further.

3
show your autolayout constraints. - Shoaib
i attached the images showing my autolayout constraints - tommy chheng
Add trailing space from UILabel to UIImage. And add width constraint to you UIImage - Candost

3 Answers

1
votes

Add trailing from UILable to UIImage with constant value 5 and relation less than and equal to (<=).

1
votes

Three things can be done.

  1. Provide a trailing space for the label to the image view. This will make sure that the label always gets truncated if text grows up.
  2. Provide a trailing space for the label to the cell's content view with the constraint constant set to the image view plus margins, if any.
  3. Keep the current configuration but take an IBOutlet and set its preferred width(found in 2nd last tab of the navigator.) to the screen width minus the image width. This will make sure that your label grows with the text but never exceeds the image.
0
votes

Add constraint between:

1) UIImage and the table cell (the container view)

2) UILabel and the UIImage

3) and finally one between tableCell and UILabel

This way you will have your UILabel stretching from the left side of the cell all the way to the image view, and truncate the text that doesnt fit into the label.