以前,写了一篇:UIWebView中显示本地图片的方法,本文是用了另一种方式实现相同的功能。
对于UIWebView,可以通过loadRequest或者loadHTMLString来加载页面,但是,这两种方法都不能直接加载本地的图片。如果需要在UIWebView中显示本地的图片,需要先将图片进行Base64编码,转成Base64的字符串,然后按照以下方式来加载UIWebView:
NSString *imgStr = [Utils image2String:[UIImage imageNamed:@"facebook.png"]]; NSString *str = [[NSString alloc] initWithFormat:@"<html><h3>Boyce Optometry:'Helping you achieve and maintain your maximum visual potential'.</h3><body>Boyce Optometry Contact Lens Centre is located in the beachside community of Burleigh Heads, right in the centre of Australia's fastest growing city, the Gold Coast.<br/>We are INDEPENDENT optometrists and have practiced in this location for over 20 years.<br/><img src='data:image/png;base64,%@'/><br/>INDEPENDENCE means we are NOT RESTRICTED by commercial corporate pressures, and are free to obtain the very best optical treatment for our patients needs, from wherever it is available.</body></html>", imgStr]; [webView loadHTMLString:str baseURL:nil]; [str release];
至于如何将图片转成Base64的字符串,请参考:将图片进行Base64编码后传输
相关推荐
在UIWebView中加载本地图片,http://blog.csdn.net/zhangao0086/article/details/7262192
uiwebview加载各种本地文件(通过loadData方法): UIWebView加载内容的三种方式: 1 加载本地数据文件 指定文件的MIMEType 编码格式使用@“UTF-8” 2加载html字符串(可以加载全部或者部分html文件) 3加载...
详情请参考http://blog.csdn.net/hursing/article/details/12868109
IOS开发中因为引入cocos2dx,导致代码审核不通过无法提交( Apple will stop accepting submissions of apps that use UIWebView APIs )。该问题的解决方案有两种:1)升级Cocos2dx的版本,在查看Cocoas官网及Cocoas...
因此,实现用户触击UIWebView页面中的链接,并跳至Safari中打开链接页面的步骤如下: 定义实现UIWebViewDelegate协议的类MyWebViewDelegate(通常是由包含UIWebView的controller中实现UIWebViewDelegate协议)。 ...
UIWebView+html+css,实现UIWebView中可点击链接,并且可显示gif动画效果
iOS UIWebView URL拦截.pdf
HTML5应用程序 在 UIWebView 中显示 JQuery Mobile 的示例源代码。 基于
UIWebview使用中的js交互简单的简析 欢迎大家指点 共同学习
这是我在学习ios的过程中写的一个demo,使用UIWebView实现一个简单的浏览器
UIWebView和js交互 里边自己写了个H5方便大家理解
NSURLCache让本地数据来代替远程UIWebView请求
UIWebView Web 网页 Demo 代码
UIWebView与JS交互小例子,其中涉及APP向JS提交信息,和JS提交信息给App
参见解析自定义头像、链接、处理微博上类似 “@” 和 “#” 的特殊转义字符并在UIWebView显示的例子 http://write.blog.csdn.net/postedit/7980198
使用UIWebView和JS进行交互,可以OC操作js,也可以JS对OC进行交互
网页视图的基本使用,网络资源地址字符串的处理,UIWebView属性与协议的综合使用;
一款UIWebView的加载进度条,基于CAShapeLayer,有两种显示风格:纯颜色显示和渐变色显示