0

I want to show hyperlink with text by using Attributed string in UILabel.

I have search for that but not getting any proper result.

Is it possible to show text with hyperlink using attributed string in UILabel?

Can anyone guide me please ?

dove
  • 20,469
  • 14
  • 82
  • 108
Nikunj
  • 987
  • 11
  • 25

1 Answers1

0

Take a look at DTCoreText Import their library into your project. And then:

Import these classes in your ViewController

#import <NSAttributedString+HTML.h>
#import <DTCoreText/DTCoreTextConstants.h>

And do something like:

NSData *HTMLData = [htmlString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *optionsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], DTUseiOS6Attributes,  @"your-fontName" ,  DTDefaultFontFamily, @(12), DTDefaultFontSize, nil];

NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithHTMLData:HTMLData options:optionsDictionary documentAttributes:nil];

[infoBodyLabel setAttributedText:attrString];

And you're done!

khose
  • 743
  • 1
  • 6
  • 19