ios--UIwebView加载本地文件(支持显示图片)

1,本地的html文件一定要放到工程文件的根目录

2,html代码中的图片路径一定要是相对路径

3,下面是用UIWebView调用本地文件的方法


方法一:

- (void)viewDidLoad

{

    [super viewDidLoad];

    webView.backgroundColor = [UIColorclearColor];

    webView.scalesPageToFit =YES;

    webView.delegate =self;

    NSString *basePath = [[NSBundlemainBundle]bundlePath];

    NSString *helpHtmlPath = [basePath stringByAppendingPathComponent:@"jsIOS.html"];

    NSURL *url = [NSURLfileURLWithPath:helpHtmlPath];

    [webViewloadRequest:[NSURLRequestrequestWithURL:url]];

}


方法二:

 

    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"html"];

    NSURL *url = [NSURL fileURLWithPath:filePath];

    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    [myWebView loadRequest:request];

    [self.view addSubview:myWebView];


方法三:


 NSString
 *filePath = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"html"];

 NSString *htmlString = [NSString stringWithContentsOfFile:filePathencoding:NSUTF8StringEncoding error:nil]

 [myWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值