3

我有一个 TTTAttributedLabel 并为它指定了一个自定义属性截断标记:

NSAttributedString *atributedTruncationToken = [[[NSAttributedString alloc]
                                                     initWithString:@" More..."
                                                         attributes:@{
                                                                      NSForegroundColorAttributeName : [UIColor lightGrayColor],
                                                                      NSFontAttributeName : self.messageLabel.font,
                                                                      NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType // no effect
                                                                      }] autorelease];

  [self.messageLabel setAttributedTruncationToken:atributedTruncationToken];

它看起来很完美,但我怎样才能使令牌可点击?

(特别是,当用户单击令牌时,我需要扩展标签,而不是标签的其余部分)。

更新。 正如我所发现的,可以(iOS 7+)添加指向令牌的链接,如下所示:

NSAttributedString *atributedTruncationToken = [[[NSAttributedString alloc]
                                                     initWithString:@" More..."
                                                         attributes:@{
                                                                      NSForegroundColorAttributeName : [UIColor lightGrayColor],
                                                                      NSFontAttributeName : self.messageLabel.font,
                                                                      NSLinkAttributeName : [NSURL URLWithString:@"..."]
                                                                      }] autorelease];

但是 TTTAttributed 标签中存在一种错误(?),令牌仍然无法点击,但n = token length标签文本的最后 n ( ) 个字符可以!

4

1 回答 1

0

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:27:19.640 回答