TTTAttributedLabel “Read More >” tail truncation with several attributes possible?

旧时模样 提交于 2019-12-07 18:09:01

问题


TTTAttributedLabel support a custom truncation string via truncationTokenString as well as truncationTokenStringAttributes.

However, I am wanting to go a bit further and set several string attributes on the truncation string, including different fonts and colours. This is what I am trying to achieve:

The arrow at the end can be achieved using a font icon, so I was thinking of the following string:

@"… Read More >"

'HORIZONTAL ELLIPSIS' (U+2026) + Read More + > character from a font.

Unfortunately TTTAttributedLabel doesn't allow me to set the ranges for various attributes.

Does anyone have a good solution for this or will have have to do it manually and basically calculate the string as it can be drawn on two lines including the @"… Read More >" string.

Thanks!


回答1:


I'm just answering my own question in case anyone stumbled onto it needing the same functionality.

At the time of posting the question TTTAttributedLabel only supported setting attributes on the whole truncation token string.

I added functionality for NSAttributedString support (for which you can specify ranges, which was missing from the plan NSDictionary with attributes approach) and submitted a pull request. It hasn't yet been merged into the main branch for TTTAttributedLabel, but in case anyone's in need of the same functionality you can find the PR here:

https://github.com/runmad/TTTAttributedLabel/commit/628de3f9cb688eb58fffdbb6e7ff81fa0d8b7f4a



来源:https://stackoverflow.com/questions/20272829/tttattributedlabel-read-more-tail-truncation-with-several-attributes-possibl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!