`
jsntghf
  • 浏览: 2477717 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

在UIWebView中显示本地图片

    博客分类:
  • iOS
阅读更多

以前,写了一篇: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编码后传输

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics