IOS..读取本地HTML文档

#import  <UIKit/UIKit.h>

 #import  “LoadLocalHtmlViewController.h”



@interfaceLoadLocalHtmlViewController : UIViewController {

    IBOutlet UIWebView*myWebView;

}

@property(nonatomic,retain) UIWebView *myWebView;       

-(IBAction)LoadLocalHtmlFile:(id)sender;

@end

 

 #import  “LoadLocalHtmlViewController.m“

 

@synthesizemyWebView;

-(IBAction)LoadLocalHtmlFile:(id)sender{ 

    //取得欲读取档案的位置与文件名

    NSString *resourcePath = [[NSBundle mainBundle] resourcePath];

    NSString *filePath =[resourcePath stringByAppendingPathComponent:@"readme.html"];



    //encoding:NSUTF8StringEncoding error:nil 这一段一定要加,不然中文字会乱码

    NSString*htmlstring=[[NSString alloc] initWithContentsOfFile:filePath  encoding:NSUTF8StringEncodingerror:nil];  

    [myWebViewloadHTMLString:htmlstring baseURL:[NSURL fileURLWithPath:[ [NSBundle mainBundle] bundlePath]]];

}

-(void)dealloc {

    [myWebView release];

    [super dealloc];

}
readme.html中添加:

<SCRIPTLANGUAGE="JavaScript">

<!--

document.onload= function(){

        document.ontouchmove = function(e){ e.preventDefault(); //-->

</SCRIPT>

 

IOS..读取本地HTML文档,布布扣,bubuko.com

IOS..读取本地HTML文档

上一篇:iOS缩放、旋转UIButton


下一篇:02 IPy模块的应用