TTTAttributedLabel“阅读更多>";有几种属性的尾部截断可能吗? [英] TTTAttributedLabel "Read More >" tail truncation with several attributes possible?
问题描述
TTTAttributedLabel 支持通过truncationTokenString
和truncationTokenStringAttributes
的自定义截断字符串. >
但是,我想进一步介绍一下,并在截断字符串上设置几个字符串属性,包括不同的字体和颜色.这是我要实现的目标:
可以使用字体图标来实现末尾的箭头,因此我想到了以下字符串:
@"… Read More >"
'HORIZONTAL ELLIPSIS' (U+2026)
+ Read More
+ > character from a font
.
不幸的是, TTTAttributedLabel 不允许我设置各种属性的范围.
有人对此有一个好的解决方案,还是必须手动完成它,并且基本上可以计算出该字符串,因为它可以在包括@"… Read More >"
字符串的两行上绘制.
谢谢!
我只是在回答自己的问题,以防有人偶然发现它需要相同的功能.
发布问题时,TTTAttributedLabel
仅在整个截断令牌字符串上支持设置属性.
我添加了支持NSAttributedString的功能(您可以为其指定范围,该计划在具有属性方法的计划NSDictionary中是缺少的),并提交了请求请求.它尚未被合并到TTTAttributedLabel
的主分支中,但是如果任何人需要相同的功能,则可以在这里找到PR:
https://github.com/runmad/TTTAttributedLabel/commit/628de3f9cb688eb58fffd6>/p> TTTAttributedLabel support a custom truncation string via 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: 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 Thanks! I'm just answering my own question in case anyone stumbled onto it needing the same functionality. At the time of posting the question 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 https://github.com/runmad/TTTAttributedLabel/commit/628de3f9cb688eb58fffdbb6e7ff81fa0d8b7f4a 这篇关于TTTAttributedLabel“阅读更多>";有几种属性的尾部截断可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!truncationTokenString
as well as truncationTokenStringAttributes
.@"… Read More >"
'HORIZONTAL ELLIPSIS' (U+2026)
+ Read More
+ > character from a font
.@"… Read More >"
string.TTTAttributedLabel
only supported setting attributes on the whole truncation token string. TTTAttributedLabel
, but in case anyone's in need of the same functionality you can find the PR here: