标签:class blog code http tar get
在一款项目里添加阅读各种文档功能 那么对在线的文档或者是下载后的文档 进行阅读,比如 doc/docx/xls/pdf等文件
有两种方法总结如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 |
1.- (void)viewDidLoad{ [super
viewDidLoad]; webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, Phone_Weight, Phone_Height)]; [self
loadDocument:@"1.docx"
inView:webView]; webView.scalesPageToFit=YES;//点击伸缩效果的 webView.delegate=self;}- (void)webViewDidFinishLoad:(UIWebView *)webView1{ [self.view addSubview:webView1];}2.- (void)viewDidLoad{ [super
viewDidLoad]; webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, Phone_Weight, Phone_Height)]; webView.scalesPageToFit=YES;//点击伸缩效果的 NSString
*documentLocation=[[NSBundle
mainBundle]pathForResource:@"1"
ofType:@"docx"]; NSURL
*myDocument=[NSURL
fileURLWithPath:documentLocation]; NSURLRequest
*request=[NSURLRequest
requestWithURL:myDocument]; [webView loadRequest:request]; webView.delegate=self;}- (void)webViewDidFinishLoad:(UIWebView *)webView1{ [self.view addSubview:webView1];} |
|
1 |
webView.scalesPageToFit=YES;这句很重要,不然 读出的文档不能很好的适应屏幕<br>还有一点,在工程中添加测试文档时候要在Add to targets第一项打对勾 不然路径无效,如图: |

|
1 |
效果图如下:(doc文件) |

|
1 |
<br><br> |
IOS 使用webview 显示 doc/docx/xls/pdf等,布布扣,bubuko.com
IOS 使用webview 显示 doc/docx/xls/pdf等
标签:class blog code http tar get
原文地址:http://www.cnblogs.com/someonelikeyou/p/3779286.html