- 浏览: 315401 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
gongfengying:
你这东西直接拷贝过来,还一大堆注释的代码,而且没有解释说明,怎 ...
Nginx图片服务器 -
wiwi1024:
PerfectHand 写道为什么没有 sql那一部分呢 求s ...
Ibatis批量插入数据 -
wenxin2009:
sql那部分就跟平常sql一样,一个update语句
Ibatis批量插入数据 -
PerfectHand:
为什么没有 sql那一部分呢 求sql 那一部分
Ibatis批量插入数据 -
heliang0915:
有源代码吗?麻烦上传一下,谢谢了!
Spring MVC与Mongodb整合开发实例
UIWebView加载html并调用js,html中需动态行进传值,用字符串格式方式动态添加,下面代码中有相关实现.
stringByEvaluatingJavaScriptFromString方法作用是返回运行后js结果,使用请见代码。
// // ViewController.h // WebViewTest // UIWebView加载html并调用js // Created by on 12-10-30. // Copyright (c) 2012年 __MyCompanyName__. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController<UIWebViewDelegate> @property (weak, nonatomic) IBOutlet UIWebView *webView; @property (strong,nonatomic) NSMutableArray *arrayLanguages; #pragma 方法 //创建webView内容方法 - (void)createWebViewContent; //创建语言界面页 - (NSString*)createLanguagePage; //返回运行后js结果 - (void)executeJSFunction:(NSString *)js; @end
// // ViewController.m // WebViewTest // // Created by on 12-10-30. // Copyright (c) 2012年 __MyCompanyName__. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize webView; @synthesize arrayLanguages; - (void)viewDidLoad { [super viewDidLoad]; arrayLanguages = [[NSMutableArray alloc] initWithCapacity:25]; [self createWebViewContent]; } //创建web内容 - (void)createWebViewContent{ NSString *homePath = [[NSBundle mainBundle] executablePath]; NSArray *strings = [homePath componentsSeparatedByString: @"/"]; NSString *executableName = [strings objectAtIndex:[strings count]-1]; NSString *rawDirectory = [homePath substringToIndex: [homePath length]-[executableName length]-1]; NSString *baseDirectory = [rawDirectory stringByReplacingOccurrencesOfString:@" " withString:@"%20"]; NSString *imagePath = [NSString stringWithFormat:@"file://%@/map.png",baseDirectory]; NSLog(@"imagePath: %@",imagePath); NSString *htmlFile = [NSString stringWithFormat:@"file://%@/welcome.html",baseDirectory]; NSLog(@"htmlFile: %@",htmlFile); NSURL *url = [NSURL URLWithString: htmlFile]; NSData *fileData = [NSData dataWithContentsOfURL:url]; //NSData *fileData = [NSData dataWithContentsOfFile:htmlFile]; NSLog(@"fileData: %@",fileData); NSString *htmlContent = [[NSMutableString alloc] initWithData: fileData encoding:NSUTF8StringEncoding]; NSLog(@"htmlContent: %@",htmlContent); NSString *langContent = [self createLanguagePage]; //通过字符串方式还对html进行动态传值 NSString* string = [NSString stringWithFormat: htmlContent,imagePath,langContent]; NSLog(@"string:%@",string); //Load the HTML String on UIWebView [self.webView loadHTMLString:string baseURL:nil];//加载html字符串到UIWebView上(该方法极为重要) //Adjust position CGRect bounds = [[UIScreen mainScreen] bounds]; int screenWidth = bounds.size.width; int screenHeight = bounds.size.height; self.webView.frame = CGRectMake(0, 20,screenWidth, screenHeight); } //创建语言显示页 - (NSString*)createLanguagePage{ arrayLanguages = [[NSMutableArray alloc] initWithObjects: @"English",@"Deutsch",@"Français",@"Español",@"Italiano",@"Pусский",@"日本語",@"中文", @"العربية",@"বাংলা",@"ελληνικά",@"हिन्दी",@"한국어",@"Bahasa Indonesia",@"Nederlands",@"Norsk", @"اردو",@"Polski",@"Português",@"Svenska",@"தமிழ்",@"Česky",@"Türkçe",@"Tiếng Việt",@"עברית>",nil]; NSMutableString* string =[[NSMutableString alloc]initWithCapacity:1024]; //init a mutable string, initial capacity is not a problem, it is flexible for(int i = 0; i < [arrayLanguages count]; i++){ [string appendString:@"<a href=\"javascript:void(0)\" "]; [string appendString:@"style=\"color:grey;text-decoration: none; "]; [string appendString:@"font-family:'Helvetica'; font-size:14px;\" "]; [string appendString:[NSString stringWithFormat: @" onMouseDown=\"imageClicked('L%d')\">%@</a>", i,[arrayLanguages objectAtIndex:i]]]; [string appendString:@" | "]; if(i%3 == 0) [string appendString:@"<br>"];//换行 } return string; } //返回运行后js结果 - (void)executeJSFunction:(NSString *)jsCommand{ NSString *result = [self.webView stringByEvaluatingJavaScriptFromString:jsCommand]; NSLog(@"result:%@",result); } //webview开始加载请求 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ //linking the javascript to call the iPhone control NSString *url = request.mainDocumentURL.relativePath; if(url != nil) { NSLog(@"url:%@",url); NSArray *strings = [url componentsSeparatedByString: @"/"]; NSString *token = [strings objectAtIndex:[strings count]-1]; NSString *text = @""; if([token hasPrefix:@"L"]){ int i = [[token substringFromIndex:1] intValue]; text = [NSString stringWithFormat:@"language:%@ be selected", [arrayLanguages objectAtIndex:i]]; }else{ text = [NSString stringWithFormat:@"Area:%@ be selected",token]; } //执行js后,得到html里title内容(通过执行js来获取html中的内容) NSString *title = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"]; NSLog(@"title :%@",title); NSString *imgSrc = [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('topimage').src;"]; NSLog(@"imgSrc :%@",imgSrc); UIAlertView* alert= [[UIAlertView alloc]initWithTitle:@"javascript message" message:text delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; [alert show]; return FALSE; } return TRUE; } @end
welcome.html
<html> <head> <meta name = "viewport" content = "initial-scale = 1.0, user-scalable = no, width = 320"/> <title>How to build an iPhone website</title> <script> function imageClicked(i){ var clicked = true; var str = ""+i; if(str.charAt(0) != 'L'){ var id = 'area' + i; var el = document.getElementById(id); } alert("调用js : "+i); window.location="http://click/"+i; } function printStr(str){ return str; } </script> <style type="text/css"> .borderImage { -webkit-tap-highlight-color:rgba(0,0,0,0); } </style> </head> <body style="background-color: transparent;margin-top:0px;margin-left:0px"> <center> <div class="borderImage"> <img id="topimage" src="%@ " border="0" height="241" width="319" usemap="#map"> <map name=map> <area shape="rect" id="area0" coords="124,1,191,58" href="javascript:imageClicked(0)" /> <area shape="rect" id="area1" coords="36,64,97,110" href="javascript:imageClicked(1)" /> <area shape="rect" id="area2" coords="119,135,171,182" href="javascript:imageClicked(2)" /> <area shape="rect" id="area3" coords="205,26,248,60" href="javascript:imageClicked(3)" /> <area shape="rect" id="area4" coords="264,88,306,132" href="javascript:imageClicked(4)" /> <area shape="rect" id="area5" coords="272,154,313,199" href="javascript:imageClicked(5)" /> <area shape="rect" id="area6" coords="187,125,232,172" href="javascript:imageClicked(6)" /> <area shape="rect" id="area7" coords="255,1,285,26" href="javascript:imageClicked(7)" /> <area shape="rect" id="area8" coords="283,1,314,26" href="javascript:imageClicked(8)" /> </map> </div> %@ </center> </body> </html>
完整工程请见附件!
- WebViewTest.zip (124.4 KB)
- 下载次数: 138
发表评论
-
解决ios13 app后台挂起时被kill掉
2020-03-14 18:23 946今天为了解决这个问题,试了好几种方法。下面为介绍下测试的情 ... -
苹果审核社交app汇总
2019-06-27 10:58 0一款两性社交app,功能有虚拟币、会员充值。此类app只能用苹 ... -
支付宝-系统繁忙,请稍后再试。错误码ALI40247
2017-05-16 11:35 6892==========支付宝-系统繁忙,请稍后再试。错误码A ... -
Ract Native笔记
2016-12-02 15:57 808Ract Native 一、Ract Native介绍: ... -
上传图片和mp3
2016-11-11 10:23 527// // UploadImgVo.m // / ... -
iOS图片保存相册
2016-10-24 11:16 624//TODO 调置滤镜 - (void) selectFi ... -
修改ios状态栏和导航颜色
2016-10-18 15:26 6941、在info.plist中添加一个字段:view cont ... -
AFNetworking设置header
2016-09-29 13:08 1236- (void)getTopicData2 { ... -
iOS内存泄漏问题小结
2016-08-10 11:13 401iOS内存问题小结: 近来在做图片滤镜时,出现内存 ... -
UIPickerView省份城市
2016-07-05 19:58 637以下为相关代码,仅供参考: #import <UI ... -
ScrollView自动布局
2016-07-01 11:44 941UIScrollView自动布局一直是初学者比较 ... -
自定义分享界面
2015-11-21 12:22 599自定义分享界,如下图: 示例代码见附件~ -
UIScrollView添加多个UIViewController并滑动
2015-10-21 18:38 2997UIScrollView添加多个UIViewControll ... -
有关UITableView复用问题
2015-09-06 11:07 1401近来用Tableview做了一个九宫格。过程中碰到了两个ce ... -
ios问题记录
2015-08-27 10:33 798问题1. tableviewcell中图片没设 ... -
AppDelegate文件中跳转页面
2015-07-31 11:36 1119目前知道有两种方式,自己小结一下: 方式一: U ... -
自定义UINavigationController有时会有卡机情况!
2015-07-22 01:10 811在项目中,由于导航上面左边和右边按钮需自定义,为全 ... -
自定义UITableViewCell设置setFrame无效!
2015-07-22 00:58 1879今天碰到一个奇怪问题。页面结构为如下图: 由 ... -
ios中的Runtime
2015-07-02 19:07 711今天对Objective-C中的Run ... -
ios学习流水账3
2015-06-12 20:37 7871、线程两种方式: //1、新开启一个线程 [ ...
相关推荐
UIWebView+html+css,实现UIWebView中可点击链接,并且可显示gif动画效果
默认情况下UIWebView加载HTML页面后,会以页面的原始大小进行显示,亦即如果页面的大小超出UIWebView视口大小,UIWebView会出现滚动效果,而且用户只能通过滚动页面来查看不同区域的内容,不能使用手指的捏合手势来...
UIWebView 是用来加载加载网页数据的一个框,接下来通过本文给大家介绍IOS中使用UIWebView 加载网页、文件、 html的方法,对本文详情感兴趣的朋友一起学习吧
uiwebview加载各种本地文件(通过loadData方法): UIWebView加载内容的三种方式: 1 加载本地数据文件 指定文件的MIMEType 编码格式使用@“UTF-8” 2加载html字符串(可以加载全部或者部分html文件) 3加载...
在APP的混合模式开发,Android开发中有WebView作为混合模式开发的桥梁,当然在IOS中也同样有一个 UIWebView 组件来作为混合模式开发的桥梁,用过UIWebView组件的开发者都知道,当UIWebView加载显示HTML页面时,组件...
iOS开发中利用UIWebView加本地Html
根据加载的html内容,自适应高度
根据加载的html内容,自适应高度
代码很少 ,主要功能是对以UIWebView加载的html网页进行某些不想展示的模块,进行隐藏。具体看代码
iphone开发,加载html,CSS,等等,你可以加JavaScript.
基于NSURLSession NSURLProtol的UIWebView离线缓存 主要是使用苹果的黑魔法类:NSURLProtocol来对网络请求进行拦截,拦截后使用自定义的网络去加载数据后进行离线缓存。这样保证在没有网络的情况下,也能保证离线能...
对比UIWebView / WKWebView加载本地html文件,加载url,加载拆分本地的html源码,直接加载源码等方式时间消耗 #简介 存储如下:![](屏幕快照2017-02-27 16.45.35.png) 5中加载方式如下: 方法1。 //读取本地...
// 取加载html文件的标题名 NSString *title = [webView stringByEvaluatingJavaScriptFromString:@document.title]; } 出现这个问题,我首先确定是不是代码的问题,经过分析,发现代码没有改动,但这次却无法...
另外,您可以在UIWebView上调用InjectMtJavascript,但是每次加载新页面时都必须调用它,并且由于通常必须等到页面加载完成后才这样做,因此建议添加mt.js来确保它可用当您需要时。 浏览器端 在UIWebView中,您可以...
要使用它,请添加 Objective-C 库文件,然后初始化并启动队列。 在您的 HTML 或 JavaScript 文件中,导入 objQueue.js 文件,您的 Web 内容现在已连接到您的本机应用程序。 有关更详细的说明,请参阅下面的“如何...
在初级操作中,项目演示了如何加载本地HTML文件和远程URL,以及如何设置UIWebView的基本属性,如背景颜色、是否允许缩放等。进阶操作则涵盖了与JavaScript的交互,包括如何在Objective-C和JavaScript之间传递数据,如何...
通用的UIWebView新闻布局的HTML模板,作者,图片,内容,以及发布时间都有
方便加载html网页可以直接加入本地html文件可以加载网络url方便C++与JS进行交互实现了iOS的UIWebView与QQuickItem的完美结合实现了WebView与C++连接的一个桥梁(bridge)弥补了Qt在iOS开发下无法使用WebView的遗憾##有...