TTTAttributedLabel可点击的截断令牌 [英] TTTAttributedLabel clickable truncation token
问题描述
我有一个TTTAttributedLabel并为其指定了一个自定义的属性截断令牌:
I have a TTTAttributedLabel and specified a custom attributed truncation token for it:
NSAttributedString *atributedTruncationToken = [[[NSAttributedString alloc]
initWithString:@" More..."
attributes:@{
NSForegroundColorAttributeName : [UIColor lightGrayColor],
NSFontAttributeName : self.messageLabel.font,
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType // no effect
}] autorelease];
[self.messageLabel setAttributedTruncationToken:atributedTruncationToken];
它看起来很完美,但是如何使令牌可点击?
It looks perfect, but how can I make the token clickable?
(特别是,当用户单击令牌而不是标签的其余部分时,我需要扩展标签).
(Particularly, I need the label to expand when user clicks on the token, but not on the rest of the label).
更新. 我发现,可以(iOS 7+)向令牌添加链接,如下所示:
UPDATE. As I have found out, it is possible (iOS 7+) to add a link to the token, like the follows:
NSAttributedString *atributedTruncationToken = [[[NSAttributedString alloc]
initWithString:@" More..."
attributes:@{
NSForegroundColorAttributeName : [UIColor lightGrayColor],
NSFontAttributeName : self.messageLabel.font,
NSLinkAttributeName : [NSURL URLWithString:@"..."]
}] autorelease];
但是TTTAttributed标签中存在一种错误(?),该令牌仍然没有可点击,但是标签文本的最后n个字符(n = token length
)可以点击!
But there is kind of a bug (?) in TTTAttributed label, that the token still does not became clickable, but the n (n = token length
) last characters of the label's text do!
推荐答案
ResponsiveLabel ,是UILabel可用于配置可点击的截断令牌.
ResponsiveLabel, a subclass of UILabel can be used to configure clickable truncation token.
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];
这篇关于TTTAttributedLabel可点击的截断令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!