我有一个TTTAttributedLabel,并为它指定了一个自定义属性化截断令牌:
NSAttributedString *atributedTruncationToken = [[[NSAttributedString alloc]
initWithString:@" More..."
attributes:@{
NSForegroundColorAttributeName : [UIColor lightGrayColor],
NSFontAttributeName : self.messageLabel.font,
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType // no effect
}] autorelease];
[self.messageLabel setAttributedTruncationToken:atributedTruncationToken];它看上去很完美,但我如何才能使令牌可点击呢?
(特别是,当用户单击令牌时,我需要扩展标签,而不是在标签的其余部分)。
UPDATE.正如我所发现的,可以(iOS 7+)添加到令牌的链接,如下所示:
NSAttributedString *atributedTruncationToken = [[[NSAttributedString alloc]
initWithString:@" More..."
attributes:@{
NSForegroundColorAttributeName : [UIColor lightGrayColor],
NSFontAttributeName : self.messageLabel.font,
NSLinkAttributeName : [NSURL URLWithString:@"..."]
}] autorelease];但是有一种错误(?)在TTTAttributed标签中,标记仍然不能被点击,但是标签文本的最后一个字符却是n (n = token length)!
发布于 2015-08-05 08:27:19
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];https://stackoverflow.com/questions/30858370
复制相似问题