开发者

Good file type for displaying text and images in a UIWebView

开发者 https://www.devze.com 2023-01-24 04:40 出处:网络
A UIWebView can be used to display a variety of file types (ex: a.xls .key.zip .numbers.zip .pages.zip .pdf .ppt .doc .rtf .rtfd.zip .key .numbers and .pages).

A UIWebView can be used to display a variety of file types (ex: a.xls .key.zip .numbers.zip .pages.zip .pdf .ppt .doc .rtf .rtfd.zip .key .numbers and .pages).

I am working on a "How to use this application" part of my app and would like to find a good file type (stored locally) for displaying some text and images in a UIWebView.

The problem is lack of control over the final result. For example,开发者_如何学运维 text size seems to have no effect in either a .rtf or .doc file. I want to have a reasonable amount of control over the text and image properties. I could use a pdf, but I don't like the way the pdf's are framed, making everything that much smaller on the screen.

Does anyone have any experience displaying various file types in a UIWebView. What file type enables good creative control over the final result?


I would use 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 a process like this

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];


Using html is the simplest alternative. But PDF is the most flexible solution. What I did on a project once was to use Core Graphics CGContextDrawPDFPage to render pdf's. It's very well documented in the Quartz 2D Programming Guide. The section name is "PDF Document Creation, Viewing, and Transforming". Once you have it working, you can use any software that exports to pdf for creating your content.


I would definitely use HTML for this purpose, its gives you dual flexibility you can either load from a pre cached file that is bundled with your application, or for a dynamic faq this can be hosted on a webserver and delivered from there

If you wrap UIWebView up on a controller, you can then do simple pieces of code like the following

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

or

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

Where the open URL method looks something like

- (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 a full screen UIWebView


You could use the UIWebView method:

loadData:MIMEType:textEncodingName:baseURL:

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

HTML is the best format to use as that's what the webview was originally made for. And HTML offers a wide amount of function and looks.


Since you're using a UIWEbView I suggest you look into CSS. Webkit has been coded so that CSS will look the closest possible to native code rendering.

You will also have the advantage of using Apple's heavy support of that feature. If you use a format from Adobe or Microsoft in iOS you're already creating an obstacle for yourself

If you're looking into displaying a neat high definition image in a UIWebView here's a good advice on the Incubator : http://iphoneincubator.com/blog/windows-views/display-images-in-uiwebview

0

精彩评论

暂无评论...
验证码 换一张
取 消