1

I am making a custom TableViewCell with a couple of elements, listed below in order from left to right:

  1. Username - UILabel (@IBOutlet)
  2. "is going to" - UILabel (static)
  3. Venue - UILabel (@IBOutlet)
  4. Timestamp - UILabel (@IBOutlet)
  5. Image - UIImage (@IBOutlet)

My problem is that I cannot figure out how to set Autolayout so that Venue (element 3) can truncate itself before overlapping onto Timestamp (element 4).

I can set the width of Venue, and this fixes the overlap problem (in case of a long Username) but it also truncates too early if the Username is short. Please note I don't want to truncate the username as it is more important than the venue.

I've attached some images below for clarification as well as to illustrate what Autolayout constraints I'm using for Venue and for Timestamp.

In IB:

enter image description here

The problem:

enter image description here

Username (element 3) constraints:

enter image description here

Timestamp (element 4) Constraints:

enter image description here

1 Answer 1

2

You can set a constraint between venue label and timestamp label so the spacing between the two will always be >= 5

I believe it would be a trailing space constraint from venue to timestamp

2
  • Thanks, this almost works perfectly. What is happening is that in the case of a long username and venue, the timestamp doesn't appear when the view first loads, if I then scroll down and back up, the timestamp appears properly. Perhaps there is a bug of some sort?
    – SamYoungNY
    Oct 12, 2015 at 17:58
  • 1
    You'll have to put a >= width constraint on timestamp, so that the resized label will be venue
    – Leonardo
    Oct 12, 2015 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.