UIWebView - 3
来源:互联网 发布:flexikey软件如何卸载 编辑:程序博客网 时间:2024/06/11 11:12
UIWebView怎么读取本地的html? iOS提供了直接的接口,但是要读取一张图片,例如
通常我们没有网络的提醒图片,参考:
http://blog.csdn.net/cuibo1123/article/details/38496025
先写个网络检测:
+ (BOOL)isExistenceNetwork{ BOOL isExistenceNetwork; SYReachability *reachability = [SYReachability reachabilityForInternetConnection]; switch([reachability currentReachabilityStatus]) { case NotReachable: isExistenceNetwork = FALSE; break; case ReachableViaWWAN: isExistenceNetwork = TRUE; break; case ReachableViaWiFi: isExistenceNetwork = TRUE; break; } return isExistenceNetwork;}
#import "NSString+Helper.h"@implementation NSString (SYSDKHelper)+ (NSString *)htmlForJPGImage:(UIImage *)image{ NSData *imageData = UIImageJPEGRepresentation(image,1.0); NSString *imageSource = [NSString stringWithFormat:@"data:image/jpg;base64,%@",[imageData base64Encoding]]; return [NSString stringWithFormat:@"<img src = \"%@\" />", imageSource];}@end
最后将它HTML转码化:
UIImage *selectedImage = UIImageFromSDKResourceBundle(@"sy_webview_neterror", @"png");NSString *stringImage = [NSString htmlForJPGImage:selectedImage];NSString *contentImg = [NSString stringWithFormat:@"%@", stringImage];NSString *content =[NSString stringWithFormat: @"<html>" "<head>" "<meta charset='utf-8'>" "<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0'>" "<style> html,body{ height: 100%; width: 100%; } img{ width:300; height: 300; position: absolute;}" "</style>" "</head>" "<body>" "%@" "</body>" "</html>" , contentImg];[self.myWebView loadHTMLString:content baseURL:nil];
这样就行了。
0 0
- UIWebView - 3
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebview
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- UIWebView
- oracle笔记
- The Castle
- 旋转矩阵和旋转向量
- 想知道站点是否被惩罚?这些数据赶紧研究!
- 将n位2进制字符串转换为10进制字符串的办法(不直接转化成整数)
- UIWebView - 3
- 大话设计模式学习笔记
- 成员函数
- Dom4j 解析XML实例
- 图片标记
- 做个优雅的码农
- Nginx + CGI/FastCGI + C/Cpp
- Android实际开发问题09_微信的授权登录
- Maven依赖排除 禁止依赖传递 取消依赖的方法