UIWebView加载html标签
来源:互联网 发布:山东半岛城市群知乎 编辑:程序博客网 时间:2024/05/20 19:47
最近遇到一个蛋疼的问题,请求下来的是一堆html标签,
2.设置webView内容宽度等于屏幕宽度显示,设置webView的缩放效果
content = "<p style=\"text-align: center;\">\n\t<span style=\"color: rgb(0, 176, 240); font-size: 13px;\">“</span></p>\n<p>\n\t<span style=\"color: rgb(0, 176, 240); font-size: 13px;\">\U4eb2\U7231\U7684\U5927\U670b\U53cb\U548c\U5c0f\U670b\U53cb\U4eec\Uff0c\U4f60\U4eec\U5728\U5514\U5494\U627e\U5230\U5fc3\U4eea\U7684\U5e7c\U513f\U56ed\U4e86\U5417\Uff1f\U5982\U679c\U6ca1\U6709\Uff0c\U770b\U5b8c\U8fd9\U7bc7\U540e\U8fd4\U56de“\U5730\U56fe”\U754c\U9762\U518d\U53bb\U6252\U4e00\U6252\U5427\Uff01</span></p>\n<p style=\"text-align: center;\">\n\t<span style=\"color: rgb(0, 176, 240); font-size: 13px;\">“</span></p>\n<section class=\"135editor\" data-color=\"rgb(89, 195, 249)\" data-custom=\"rgb(89, 195, 249)\" data-id=\"46\" style=\"padding: 0px; border: 0px currentColor; position: static; box-sizing: border-box;\">\n\t<section style=\"margin: 0px; padding: 0px; box-sizing: border-box;\">\n\t\t<section style=\"padding: 0px; text-align: center; color: inherit; line-height: 20px; margin-top: 0.5em; vertical-align: top; display: inline-block; box-sizing: border-box;\">\n\t\t\t<img alt=\"\U5514\U5494logo1.png\" src=\"http://image2.135editor.com/cache/remote/aHR0cHM6Ly9tbWJpei5xbG9nby5jbi9tbWJpei9qV2tCcmFmbWFacHJUanRsWHNmbTJqdDJTNGNuc3hKMGliWmxqV2Y1aWNkWGljNzEyNjN1M3phRFl0bkNVOGlhQktaRE1ZbEcwcmg5clNXUlZ0WFBQWlRRd0EvMA==\" style=\"width: 40px; height: auto !important; vertical-align: top;\" title=\"\U5514\U5494logo1.png\" />\n\t\t\t<p class=\"135brush\" data-brushtype=\"text\" placeholder=\"135\U7f16\U8f91\U5668\" style=\"margin: 0px; padding: 0px; color: inherit; line-height: 30px; font-size: 12px; box-sizing: border-box;\">
没遇到过啊,在网上找了去标签的代码 ,试了之后发现图片没了,不行,找了第三方的解析html的库,发现解析的是网页链接,似乎也不行。。。。。。。
彻底蒙了,。。。。。。。。
问了问一位Android的大神 ,他说他们用webView。。。。。webView?
UIWebView * webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64)]; webView.delegate=self; [self.view addSubview:webView]; NSURL *url = [NSURL URLWithString:@"http://192.168.1.106:8080/MJServer/"]; webView.delegate = self; [webView loadRequest:[NSURLRequest requestWithURL:url]];webView 不是这么用吗?
查了查webView的代理方法 发现了一个
- (void)loadHTMLString:(NSString *)string baseURL:(nullable NSURL *)baseURL;好像就是, 于是就试了试,代码如下,
NSString * infoString =[NSString stringWithFormat:@"%@ %@%@ %@",[infoDic objectForKey:@"title"],@"<br>",[infoDic objectForKey:@"createDate"],[infoDic objectForKey:@"content"]]; UIWebView * webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64)]; webView.delegate=self; [self.view addSubview:webView]; [webView loadHTMLString:infoString baseURL:nil];
<br>的作用:因为标题和时间是键值对的形式传过来的, 所以我需要一个空格, <br>就是空格。
此外 webView 还可以加载PDF文档 ,text文档 本地网页, 形式都一样,瞬间感觉webView原来是一个高大上的东西啊 。。。。。。。。。
设置UIWebView的缩放比
- (void)webViewDidFinishLoad:(UIWebView *)webView{ [webView stringByEvaluatingJavaScriptFromString:@"document.body.style.zoom=0.9"];}
1.设置字体
-(void)webViewDidFinishLoad:(UIWebView *)webView{ [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '40%'"];//修改百分比即可}
2.设置webView内容宽度等于屏幕宽度显示,设置webView的缩放效果
NSString *meta = [NSString stringWithFormat:@"document.getElementsByName(\"viewport\")[0].content = \"width=self.view.frame.size.width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\""]; [webView stringByEvaluatingJavaScriptFromString:meta];//(initial-scale是初始缩放比,minimum-scale=1.0最小缩放比,maximum-scale=5.0最大缩放比,user-scalable=yes是否支持缩放)
0 0
- UIWebView加载html标签
- 基于UIWebview加载html代码 并获取标签
- UIWebView加载html
- uiwebView 加载html字符串
- UIWebView加载html
- UIWebView加载本地html
- UIWebView加载本地html
- UIWebView 加载 HTML
- uiwebview加载html代码
- UIWebView加载本地html
- UIWebView加载本地html
- UIWebView加载html(转)
- UIWebView(Javascript)Html标签操作
- UIWebView加载本地HTML文件
- UIWebView加载本地html ios
- UIWebView(一):加载html
- UIwebview加载本地html文件
- html代码加载到UIWebView
- 经常用到的视觉差parallax
- Win7安装 boost库
- 搜索引擎这样用才有效率
- 安卓仿微信左右滑动点击切换页面和图标
- 文章标题
- UIWebView加载html标签
- 对linux下的服务端程序做profile
- 数据结构4.进一步封装的双向链表
- java函数参数后面加三个点——可变长度参数列表
- MongoDB学习笔记
- 关闭Eclipse的控制台console自动跳出
- IE8下jquery报错:意外地调用了方法或属性访问。
- BZOJ NOI十连测第一场
- C++程序设计语言练习7.9 迭代器的使用