I need a UILabel subcass with multiline attributed text with support for links, bold styles, etc. I also need tail truncation with an ellipsis. None of the open source code that supports attributed text inside UILabels (TTTAttributedLabel
, OHAttribuedLabel
, TTStyledTextLabel
) seem to support tail truncation for multi-line text. Is there an easy way to get this?
|
||||
add a comment
|
Hi I am the developer of There is no easy way to achieve this (as explained in the associated issue I opened on the github repository of my project), because CoreText does not offer such feature. The only way to do this would be to implement the text layout yourself using CoreText objects (CTLine, etc) instead of using the I would really appreciate if someone propose a solution to do this propery as it seems a bit of work to do and you have to manage a range of special/unusual cases too (emoji cases, fonts with odd metrics and unusual glyphs, vertical alignment, take into account the size of the ellipsis itself at the end to know when to stop). So feel free to dig around and try to implement the framing of the lines yourself it would be really appreciated! |
||||
Based on what I found here and over at https://groups.google.com/forum/?fromgroups=#!topic/cocoa-unbound/Qin6gjYj7XU, I came up with the following which works very well.
|
CTTypesetterSuggestLineBreak
function which will suggest a line break on an attributed string for a given width. This width could be calculated on the last CTLine by calculating the width of the ellipsis with the same attributed string and it seems like most of your above special cases would then be handled properly. – John Wright Oct 6 ‘11 at 11:19