TTTAttributedLabel: Bug when adding link to truncation attributed string
The link attributed isn’t added to the attributed truncation token correctly.
- (void)viewDidLoad {
[super viewDidLoad];
NSString *text = @"The NSString class declares the programmatic interface for an object that manages immutable strings. An immutable string is a text string that is defined when it is created and subsequently cannot be changed. NSString is implemented to represent an array of Unicode characters, in other words, a text string.";
for (int i = 0; i < 10; i++) {
TTTAttributedLabel *l1 = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(10, 10*(i+1) + (i * 50) + 10, self.view.bounds.size.width - (i +1)*20, 50)];
l1.delegate = self;
l1.userInteractionEnabled = YES;
l1.numberOfLines = 2;
l1.attributedTruncationToken = [[NSAttributedString alloc] initWithString:@"...more" attributes:@{NSForegroundColorAttributeName : [UIColor blueColor],
NSLinkAttributeName : [NSURL URLWithString:@"http://more.com"]}];
// l1.backgroundColor = [UIColor redColor];
l1.text = text;
[self.view addSubview:l1];
l1.layer.borderColor = [UIColor redColor].CGColor;
l1.layer.borderWidth = 2;
}
}
- (void)attributedLabel:(TTTAttributedLabel *)label
didSelectLinkWithURL:(NSURL *)url {
NSLog(@"Here");
}
Notice that the link underlines are also not placed in the correct locations

About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 23 (6 by maintainers)
Commits related to this issue
- [Tests] Added #519's truncation sizing test — committed to TTTAttributedLabel/TTTAttributedLabel by jhersh 9 years ago
- [Truncation] Corrected token link range (fixes #537) #518 #519 — committed to TTTAttributedLabel/TTTAttributedLabel by jhersh 9 years ago
- https://github.com/TTTAttributedLabel/TTTAttributedLabel/issues/519 — committed to darkFunction/TTTAttributedLabel by darkFunction 7 years ago
- Fixed Bug when adding link to truncation attributed string #519 https://github.com/TTTAttributedLabel/TTTAttributedLabel/issues/519 — committed to mendaparadarshit/TTTAttributedLabel by mendaparadarshit 4 years ago
- fix issue: truncation string is not incorrect range fix issue: truncation string is not incorrect range https://github.com/TTTAttributedLabel/TTTAttributedLabel/issues/519 — committed to karosLi/TTTAttributedLabel by karosLi 3 years ago
I fix it, add on line code at line 870, I will make a pull request later, maybe I need to change the unit test code later.
@shaikshabana I known, you must reset TTTAttributedLabel, eg.
remove old links, special “text = nil”
@jhersh I know how to reproduce the bug, Just tap the
...More, the blue text will appearI still get this issue with attributedTruncationToken,can anybody help me to resolve this