问题
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