Objective-C Learning Notes - UIWebView2
使用 UIWebView 加载/显示 PDF Word JPEG 文件
关键代码:
PDF:
NSString *path = [[NSBundle mainBundle] pathForResource: @"fileName" ofType: @"pdf"]; NSData *data = [NSData dataWithContentOfFile: path]; [myWebView loadData: data MIMEType: @"application/pdf" textEncodingName:nil baseURL: nil];
JPEG:
NSString *path = [[NSBundle mianBundle] pathForResource: @"fileName" ofType: @"jpg"]; NSData *data = [NSData dataWithContentOfFile: path]; [myWebView loadData: data MINEType: @"application/jpeg" textEncodingName: nil baseURL: nil];
DOC:
NSString *path = [[NSBundle mainBundle] pathForResource: @"fileName.doc" ofType: nil]; NSURL *url = [NSURL fileURLWithPath: path]; URLRequest *request = [NSURLRequest requestWithURL: url]; [myWebView loadRequest: request];