Good file type for displaying text and images in UIWebView

UIWebView can be used to display various types of files (for example: a.xls.key.zip.numbers.zip.pages.zip.pdf.ppt.doc.rtf.rtfd.zip.key.numbers and.page).

I am working on a part of the “How to Use this Application” application in my application and would like to find a good file type (stored locally) to display some text and images in a UIWebView.

The problem is the lack of control over the end result. For example, the size of the text does not seem to affect either the .rtf file or the .doc. I want to have a reasonable amount of control over the properties of text and images. I could use a pdf file, but I do not like the way of creating PDF files, doing everything that is much smaller on the screen.

Does anyone have experience displaying various file types in a UIWebView. What type of file gives good creative control over the end result?

+4
source share
5 answers

I would use the good old html . It has great support in UIWebview (duh), and is relatively easy to learn and create.

Update:

To display a local file from a UIViewController, use such a process

UIWebView *myWebView = [[UIWebView alloc] initWithFrame:self.view.frame]; [view loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"documentation" ofType:@"html"]]]]; while ([view isLoading]) { // wait... } [self.view.addSubview:myWebView]; [view release]; 

Or, for a remote file:

 UIWebView *myWebView = [[UIWebView alloc] initWithFrame:self.view.frame]; [view loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.myserver.com/ios/documentation/documentation.html"]]]; while ([view isLoading]) { // wait... } [self.view.addSubview:myWebView]; [view release]; 
+8
source

Using html is the easiest alternative. But PDF is the most flexible solution. What I once did in the project was using Core Graphics CGContextDrawPDFPage to render PDF files. This is very well documented in the 2D Quartz Programming Guide. The title of the section is "Creating, Viewing, and Converting a PDF Document." When you work, you can use any software that is exported to pdf to create your content.

0
source

I would definitely use HTML for this purpose, it gives you double flexibility that you can either download from a pre-cached file that comes with your application, or for dynamic faq that can be hosted and delivered from a web server

If you transfer the UIWebView to the controller, you can make simple code snippets, for example, the following

 [self openURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"help" ofType:@"html"]]]; 

or

 [self openURL:[NSURL URLWithString:@"http://somedomain.com/iPhoneHelp/"]]; 

If the open URL method looks something like this:

 - (void) openURL:(NSURL *)url { HelpWebViewViewController *webView = [[HelpWebViewViewController alloc] initWithURL:url]; [self.navigationController pushViewController:webView animated:YES]; [webView release]; } 

Provide the init method on this web controller to set the URL for the full screen UIWebView

0
source

You can use the UIWebView method :

loadData:MIMEType:textEncodingName:baseURL:

And use the methods of the NSData class ( dataWithContentsOfFile:) to load data from a local file.

HTML is the best format to use as what the web view was originally created for. And HTML offers a wide range of features and views.

0
source

Since you are using UIWEbView, I suggest you look into CSS. Webkit was encoded so that CSS looked as close as possible to rendering native code.

You will also have the advantage of using Apple to support this feature. If you use the format from Adobe or Microsoft in iOS, you are already creating an obstacle for yourself.

If you are looking at a neat high-definition image in UIWebView, there is good incubator advice here: http://iphoneincubator.com/blog/windows-views/display-images-in-uiwebview

0
source

All Articles