1

Can I have UILabel truncate text similar functionality on UIWebview?

So I want to truncate the text on tail, for example

abcdefghijklmnopqrstuvwxyz1234567890

becomes

abcdefghijkl...

My UIWebview will only have one line.

Rendy
  • 5,572
  • 15
  • 52
  • 95

1 Answers1

0

It could be done by adding some CSS to the web content (for example this CSS from Truncate String with Ellipsis).

.truncate {
    width: 250px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

Otherwise, why not use a UILabel with an NSAttributedString?

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
  • Does NSAttributedString support html tag, for example ? Because I have it in my string. – Rendy Jan 08 '13 at 09:35
  • There is not support for actual HTML-tags (except on OSX where you can use initWithHTML:) but you can do all the formatting, even [subscript and superscript](http://stackoverflow.com/a/2195008/608157) on iOS. There is also some open source code available that deal with HTML parsing to attributed strings on iOS if you really need it. – David Rönnqvist Jan 08 '13 at 09:43
  • I have tried with OHAttributedLabel but it doesn't work and I just figured out it doesn't support it :( – Rendy Jan 08 '13 at 15:42
  • What version are you targeting? The native UILabel supports attributed strings since iOS 6. – David Rönnqvist Jan 08 '13 at 15:43