Thursday, February 11, 2010

Formatting UITextView

There is no feature to format the text in UITextView

We can use the UIWebView to display the formatted text
The easy two methods are :

1. - (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
2. - (void)loadRequest:(NSURLRequest *)request

1.
use the html formatted text as input.
e.g:
NSString *htmlText = @"<html><head><meta name=""viewport"" content=""width=320""/></head><body><h3>Header</h3><p>Just for testing n;</p></body</html>";
[webView loadHTMLString:htmlText baseURL:[NSURL URLWithString:@"http://www.apple.com"]];

2. Or we can load a local html file
e.g:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];

No comments:

Post a Comment