Pages

Subscribe:

Labels

Sep 14, 2010

UITextView with HTML

You must bother sometimes when you need to display a multi color text in your application! You must be using many uilabels with fissrent color. But you need not do this all. Here is a simple way to show your HTML file directly into UITextView.
What you need is to save all text into a html file and call that file in your UITextView with the help of this code bellow-

// Load the HTML source
self.sourceText = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"htmlfile" ofType:@"html"]];
[myTextView setContentToHTMLString:self.sourceText];

You may download the sample app from here

4 comments:

Pankaj P said...

Thanks for such a nice tutorials.
It helped me a lot....

Anonymous said...

setContentToHTMLString is a non-public API and my app got rejected after using this.

Dont use this

Anonymous said...

if we cant use this setContentToHTMLString method then which method we shoud use?

Anonymous said...

In spanish I want say something: "Muchas gracias por este aporte increíble, realmente son cosas tan básicas pero tan necesarias y si no existiera gente como tu, que comparte el conocimiento, no se podrían hacer cosas grandes. FELICITACIONES POR ESTE APORTE AMIGO!".

Sinceramente Patrick!.

Post a Comment