.rtf files are apparently supported but I was unable to get the UIWebView to display them properly. It would format the text correctly (size, colour, font etc) but images just plain didn't render (I tried .gif, .png and .jpg to no avail). chances are if you are going to the trouble of using .rtf, you are probably hoping to display images in the UIWebView, since the main benefit of rtf is that you can embed images into the file. This was tried on an actual iPad 1 (4.3) and on a simulated iPhone (4.3).
The code done to display the rtf in a UIWebView required the rtf to be written to a file with the rtf file extension. It refused to load the file if you use no file extension or an incorrect one so make sure you write it as .rtf.
Here is an Objective C function to take an input string (which should contain the rtf you wish to display) and get the UIWebView to load it into view...
-(void) loadRtf : (UIWebView*) webView : (std::string) rtfFile
{
// This function will write the rtf to a file in your apps bundle location on the iDevice and use
// the UIWebView to load it...
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([path count] > 0) ? [path objectAtIndex:0] : nil;
NSString *fullPath = [basePath stringByAppendingPathComponent:@"rtfData.rtf"];
std::string fp = [fullPath cStringUsingEncoding:NSASCIIStringEncoding];
std::ofstream fs;
fs.open(fp.c_str(), std::ios_base::binary);
if( !fs.is_open() )
return;
fs << rtfFile;
fs.close();
NSURL *url = [NSURL fileURLWithPath:fullPath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}