UIWebView 使用

 

UIWebView加载的html里,加载工程文件的图片 

第一种方法:

       在info.plist里面定义个URL schema比如叫 youapp,那么路径就写成youapp://test.png

可以参照http://iphonedevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html

第二种方法:

       NSString *htmlString = @"<html><head><body><img src=\"logo.png\"><body></head></html>";
       NSString *path = [[NSBundle mainBundle] bundlePath];
       NSURL *baseURL = [NSURL fileURLWithPath:path];
       [self.myWebView loadHTMLString:htmlString baseURL:baseURL];

这个html是你自己写的一个本地html文件,用来布置UIWebView界面。里面用到的图片可以是工程文件里面的,也可以是网络上的。给出Url。

解决在UIWebView中加载图片时出现延迟现象的做法

文字和图片同时显示:
NSString* showHtml = @"<html><head></head><body><img src='https://img-blog.csdnimg.cn/2022010914465968472.jpg'/><p>here is show a picture.</p></body></html>"; NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"www.abc.com/img/img1.jpg"]]; NSString* imageString = [imageData base64Encoding]; UIWebView* webView = [UIWebView alloc]; [webView loadHTMLString:[NSString stringWithFormat:showHtml, imageString] baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]]; //以下把该UIWebView显示出来的代码略

粗体的地方就是通过base64来实现的地方,我们这里显示的是jpg格式的图片,因此在img标签的src属性里面写的是“src=’data:image/jpg;base64,%@’”,而如果是其他格式的图片的话记得把对应的地方给改一下

用Javascript判断图片是否存在,不存在则显示默认图片

<img src=" http://www.iecn.net/images/logo_home.gif" http://www.cnlei.org/BLOG/styles/style2007/images/logo.gif'" />

1 当拖动超过边界,不想让其弹跳


html里面加上  document.ontouchmove = function(event){ return false; }



2 想弹出Acti*****heet,加上


[font=] html里面加上  document.documentElement.style.webkitTouchCallout = ‘none’;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值