iOS 本地加载js文件
2015-07-13 20:25 甘雨路 阅读(1260) 评论(0) 编辑 收藏 举报 1 #import "RootViewController.h"
2
3 @interface RootViewController ()<UIWebViewDelegate>
4
5 @property (nonatomic, strong)UIWebView *webView;
6
7 @end
8
9 @implementation RootViewController
10
11 - (void)dealloc
12 {
13 self.webView = nil;
14 }
15 - (void)viewDidLoad {
16 [super viewDidLoad];
17 self.view.backgroundColor = [UIColor redColor];
18 self.webView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
19 [self.view addSubview:self.webView];
20 // cli_dwr.html文件名
21 [self loadDocument:@"cli_dwr.html"];
22 }
23 // 加载本地使用说明文件
24 - (void)loadDocument:(NSString *)docName
25 {
26 NSString *mainBundleDirectory = [[NSBundle mainBundle] bundlePath];
27 NSString *path = [mainBundleDirectory stringByAppendingPathComponent:docName];
28
29 NSURL *url = [NSURL fileURLWithPath:path];
30 NSURLRequest *request = [NSURLRequest requestWithURL:url];
31 self.webView.scalesPageToFit = YES;
32 [self.webView loadRequest:request];
33 }
34
35 @end