Categories

UIWebView 显示本地html及引用资源

有些软件中可能会用到html页面,比如用在做帮助页面或者其它相关信息时。 这种情况下只需要将html页面文件以及索引用到的资源(图片、声音等) 都加入到bundle中,或者单独创建一个bundle, 在需要的时候调用UIWebView的相关方法即可

比如

1
2
3
4
5
NSBundle* bundle = [NSBundle mainBundle];
NSString*  resPath = [bunder resourcePath];
NSString* filePath = [resPath stringByAppendPathComponent:@"test.html"];
 
[WebView loadHTMLString:[NSString stringWithContentsOfFile:filePath] baseURL:[NSURL fileURLWithPath:[bundle bundlePath]]];

其中bundle可以不是mainbundle,test.html就是想要显示的页面

原创文章如转载,请注明
转载自:FLYBLOG [http://www.flyblog.info]

本文链接地址:http://www.flyblog.info/catprogramming/251.html

Leave a Reply