0

我有一个用于 iOS 6.1的带有 TTTAttributedLabel ( https://github.com/mattt/TTTAttributedLabel ) 的自定义 UITableViewCell。我使用 TTTAttributedLabel 的 truncationtokenstring 属性来格式化结尾(默认为省略号 ...),当文本太长并被截断为:“...阅读更多 >”。

我可以通过改变它的前景色等来格式化这个截断标记字符串,就像在这篇文章中一样: TTTAttributedLabel "Read More >" tail truncation with several attributes possible?

但是如何使 truncationtokenstring 成为链接,以便当用户单击“...阅读更多 >”时,我可以调用委托并显示更多信息?

4

2 回答 2

1

试图自己解决这个问题,但当前版本似乎不可能,所以我自己制作了叉子并实现了这个(可能不是最好的代码,但它可以工作)。

https://github.com/renssies/TTTAttributedLabel

它的工作方式很简单,只需在 truncationTokenStringAttributes 中添加一个 NSLinkAttributeName 即可。当然,这只是 iOS 7+。

于 2014-04-08T12:01:03.190 回答
-1

我创建了一个名为ResponsiveLabel的 UILabel 子类。您可以将样式添加到自定义截断标记以及指定点击操作。

NSString *expansionToken = @"Read More ...";
NSString *str = @"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
NSMutableAttributedString *attribString = [[NSMutableAttributedString alloc]initWithString:kExpansionToken attributes:@{NSForegroundColorAttributeName:[UIColor blueColor],NSFontAttributeName:self.customLabel.font}];
[self.customLabel setAttributedTruncationToken:attribString withAction:^(NSString *tappedString) {
  NSLog(@"Tap on truncation text");
}];
[self.customLabel setText:str withTruncation:YES];
于 2015-08-05T08:33:10.360 回答