iOS开发:加载本地文件到UIWebView的方法
关键是生成“文件URL”
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUSErDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- NSString *path = [documentsDirectory stringByAppendingPathComponent:docName];
- NSURL *url = [NSURL fileURLWithPath:path];
- NSURLRequest *request = [NSURLRequest requestWithURL:url];
- self.myWebView.scalesPageToFit = YES;
- [self.myWebView loadRequest:request];
如果是资源文件,则用获取路径
- NSString *mainBundleDirectory = [[NSBundle mainBundle] bundlePath];
- NSString *path = [mainBundleDirectory stringByAppendingPathComponent:docName];
相关推荐
AllenG 2013-07-07
好好学习天天 2020-07-21
heqiang0 2020-06-25
定格 2020-05-30
定格 2020-04-17
zhoutaifeng 2020-04-17
zhoutaifeng 2020-04-17
zhoutaifeng 2020-03-07
好好学习天天 2020-03-06
heqiang0 2020-03-02
知更鸟CoolLee 2020-02-27
发条戏子 2020-02-22
herogood 2020-02-19
好好学习天天 2020-02-17
heqiang0 2020-02-13