1

I'm using

titleLabel.Lines = 2; titleLabel.LineBreakMode = UILineBreakMode.TailTruncation;

Now long text is broken by a ... in the end.

Now I would like to know if the titleLabel is tail truncated , contains "..." ? Any easy suggestions for this ?? as I cannot see the ... characters in the actual titleLabel.Text field

Anand Suthar
  • 3,678
  • 2
  • 30
  • 52

1 Answers1

1

Your question is similar to Change the default '...' at the end of a text if the content of a UILabel doesn't fit

There is no direct option to access ellipsis(the three dot). You need to do it yourself. Code to count the size of your string, clip the string and add a ellipsis with the color you want when the string exceed the view.

Define a NSAttributesString

let atttext = NSAttributedString(string: text!, attributes: [NSForegroundColorAttributeName: UIColor.redColor()])

Calculate the size of the string

let bounds = atttext.boundingRectWithSize(label.bounds.size, options: [], context: nil)

Do something to the string when it exceed the view

if bounds.size.width > 10 {
    //Do something here, like assign a new value to `attributedText` of label or change the color
    label.attributedText = NSAttributedString(string: "Labelfdjkfdsjkfdsjkf...", attributes: [NSForegroundColorAttributeName: UIColor.blackColor()])
}

For more detail, you can have a look at the last answer of the question I mentioned above.

Community
  • 1
  • 1
ilovecomputer
  • 4,238
  • 1
  • 20
  • 33