Nic Hubbard Nic Hubbard - 3 months ago 13
iOS Question

Don't let UILabel overlap another label in UITableViewCell

I have a custom

UITableViewCell
that has a titleLabel on the left, and a detail label on the right, similar to the
Right Detail
cell type.

enter image description here

Current neither
UILabel
has a set width, which is what I want. However the
titleLabel
sometimes is very long and overlaps the detail label on the right.

How can I give a margin between the two labels, ONLY if the
titleLabel
is too long and will overlap?

Answer

The thing what you can do, is set minimum space between them by putting relation GraterThenOrEqual for example at 10 pixels. Or there is a dodgy way to it by playing with priority with constraints. You may set priority of constraint between as 750.

In the interface builder you have to set space between the labels, and then select manually this constraint, then you will see the menuenter image description here

called Relation, just choose there GraterOrEqual