Evgeniy Kleban Evgeniy Kleban - 4 months ago 10
iOS Question

Force UILabel to display 2 lines

I have UILabel that display single line if it have space for it.

However, i need to force it always display 2 lines, even if there is enough space for display it in 1 line.

Robust way is to reduce right spacing constraint and check that condition on all of available devices, but maybe there is an easier way?

To be clear, i want this:enter image description here

look like this: enter image description here

As i mentioned, now labels binded to superview by constraints.

Answer

In InterfaceBuilder settings of UILabel text press option+enter between "Справочник" and "МКБ".

Or set label.text = @"Справочник\nМКБ";.

And, of course, set yourLabel.numberOfLines = 2; (or 0) in IB or code.