3

I have to display a small portion of a long text in objective C.how we will use TTTAttributedLabel to add a Read More button to display all text.

Thanks in advance

Ziad Bou Ismail
  • 187
  • 2
  • 11

2 Answers2

4
  • Use attributedTruncationToken to set the ".. Read more" at the end of the label.
  • Set an attributed string with a link such as NSLinkAttributeName: [NSURL URLWithString:EXTagURL].

Then use the delegate method below to navigate to the URL of the attributed string you set.

-(void)attributedLabel:(TTTAttributedLabel *)label
  didSelectLinkWithURL:(NSURL *)url{}

Hope this helps.

Rafa Viotti
  • 9,998
  • 4
  • 42
  • 62
0

Firstly make sure you have updated cocoapods In your terminal:- gem install cocoapods , pod install

Then set the label to class TTTAttributed label in your storyboard. Then create an outlet to your view controller @property (weak, nonatomic) IBOutlet TTTAttributedLabel *articleDetail;

Then create an attributed string in viewdidload

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"Read More .."];
[attributedString addAttribute: NSLinkAttributeName value: [NSURL URLWithString:@""] range: NSMakeRange(0, attributedString.length)];
self.articleDetail.attributedTruncationToken = attributedString;

Then finally create delegate method

-(void)attributedLabel:(TTTAttributedLabel *)label
didSelectLinkWithURL:(NSURL *)url
{
}
vivek
  • 1
  • 4