Add reading documentation to a project read the online document or the downloaded document, such as doc/docx/xls/pdf files.
Two methods are summarized as follows:
?
| 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第一项打对勾 不然路径无效, |
?
?