Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UILabel text as html text

I am stuck with a small issue.

I need to use a sentence which will have first two words bold and last two words italic. Like:

I am using an Objective C Developer.

How to do that. Is this possible in Objective C?

like image 950
TechBee Avatar asked Sep 03 '25 15:09

TechBee


1 Answers

For iOS7 you can use this:

NSString * htmlString = @"<html><body> Some html string </body></html>";
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];

UILabel * myLabel = [UILabel alloc] init];
myLabel.attributedText = attrStr;
like image 113
sanjana Avatar answered Sep 05 '25 15:09

sanjana