Pregunta

I am working on a project that has to support both iOS6 and iOS7. My problem is it works different on different systems. I'm trying to create UILabel with number of lines equal to 2, but when I set it's line break mode to NSLineBreakByTruncatingTail it works different.

Explanation (numberOfLines = 2, text = @"long teeexxxttt"):

    iOS7                    iOS6
      NSLineBreakByWordWrapping
 ----------              ----------
|long      |            |long      |
|teeeexxxtt|            |teeeexxxtt|
 ----------              ----------

     NSLineBreakByTruncatingTail
 ----------              ----------
|long      |            |long te...|
|teeeexx...|            |          |
 ----------              ----------
     ^                       ^
     |                       |
  correct                incorrect - shows only one line

How do I fix it?

¿Fue útil?

Solución 2

The problem is iOS6 and prior won't update multiline UILabels with custom UIFont and NSLineBreakByTruncatingTail, but you can archive the same result by using autoresizing or autolayout.

Otros consejos

I know this is an old question, but I recently had the same problem. I found that with constraints I had to set the preferred width to get the ellipsis to behave properly:

yourLabel.preferredMaxLayoutWidth = width; 

UILable.preferredMaxLayoutWidth

Swift 2.1

yourLabel.text = "your text"
yourLabel.numberOfLines = 0
yourLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
yourLabel.sizeToFit()
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top