UIWebView字体根据手势放大,并让其大小根据字体多少排布
2010-08-19 09:40
274 查看
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 1024, 768, 500)];
webView.delegate = self;
NSString *headString = @"<!DOCTYPE html PUBLIC /"-//W3C//DTD HTML 4.01//EN/" /"http://www.w3.org/TR/html4/strict.dtd/">"
"<html>"
"<script language=/"javascript/">document.ontouchstart=function(){ document.location=/"myweb:touch:start/"; }; document.ontouchend=function(){ document.location=/"myweb:touch:end/"; }; document.ontouchmove=function(){ document.location=/"myweb:touch:move/"; } </script>"
"<script type=/"text/javascript/" charset=/"utf-8/">"
"var origScale;"
"var minSize = 50;"
"var maxSize = 500;"
"function newHeight() {"
"return document.body.clientHeight;"
"}"
"function boxStart(event){"
"event.preventDefault();"
"origScale = parseInt(document.getElementById('newSize').style.webkitTextSizeAdjust, 10);"
"}"
"function boxChange(event){"
"event.preventDefault();"
"size = origScale * event.scale;"
"document.getElementById('echo').innerHTML = event.scale;"
"if (size < minSize) {"
"document.getElementById('newSize').style.webkitTextSizeAdjust = minSize + '%';"
"} else if (size > maxSize) {"
"document.getElementById('newSize').style.webkitTextSizeAdjust = maxSize + '%';"
"} else {"
"document.getElementById('newSize').style.webkitTextSizeAdjust = size + '%';"
"} "
"}"
"</script>"
"<body>"
"<div id = /"newSize/" style=/"-webkit-text-size-adjust:120%/" ongesturestart=/"boxStart(event)/" ongesturechange=/"boxChange(event)/">"
"<p>";
NSString *endString = @"</p>"
"</div>"
"<div id='echo'/>"
"</body>"
"</html>";
headString = [headString stringByAppendingString:article.content];
article.content = [headString stringByAppendingString:endString];
[webView loadHTMLString:article.content baseURL:nil];
放大缩小都是利用JS在webView上实现,方法依次为,获取webView上touch事件;
获取文本内容的高度,获取上一次的高度值,重新设定高度值。
webView.delegate = self;
NSString *headString = @"<!DOCTYPE html PUBLIC /"-//W3C//DTD HTML 4.01//EN/" /"http://www.w3.org/TR/html4/strict.dtd/">"
"<html>"
"<script language=/"javascript/">document.ontouchstart=function(){ document.location=/"myweb:touch:start/"; }; document.ontouchend=function(){ document.location=/"myweb:touch:end/"; }; document.ontouchmove=function(){ document.location=/"myweb:touch:move/"; } </script>"
"<script type=/"text/javascript/" charset=/"utf-8/">"
"var origScale;"
"var minSize = 50;"
"var maxSize = 500;"
"function newHeight() {"
"return document.body.clientHeight;"
"}"
"function boxStart(event){"
"event.preventDefault();"
"origScale = parseInt(document.getElementById('newSize').style.webkitTextSizeAdjust, 10);"
"}"
"function boxChange(event){"
"event.preventDefault();"
"size = origScale * event.scale;"
"document.getElementById('echo').innerHTML = event.scale;"
"if (size < minSize) {"
"document.getElementById('newSize').style.webkitTextSizeAdjust = minSize + '%';"
"} else if (size > maxSize) {"
"document.getElementById('newSize').style.webkitTextSizeAdjust = maxSize + '%';"
"} else {"
"document.getElementById('newSize').style.webkitTextSizeAdjust = size + '%';"
"} "
"}"
"</script>"
"<body>"
"<div id = /"newSize/" style=/"-webkit-text-size-adjust:120%/" ongesturestart=/"boxStart(event)/" ongesturechange=/"boxChange(event)/">"
"<p>";
NSString *endString = @"</p>"
"</div>"
"<div id='echo'/>"
"</body>"
"</html>";
headString = [headString stringByAppendingString:article.content];
article.content = [headString stringByAppendingString:endString];
[webView loadHTMLString:article.content baseURL:nil];
放大缩小都是利用JS在webView上实现,方法依次为,获取webView上touch事件;
获取文本内容的高度,获取上一次的高度值,重新设定高度值。
相关文章推荐
- 根据html容器大小和显示文字多少调节字体大小
- 固定textview大小,根据文字多少调整字体自适应textview大小
- 根据字体多少使UILabel自动调节尺寸
- 修改UIWebView中字体的大小
- Android 根据屏幕分辨率自动调整字体大小
- 根据字体多少使UILabel自动调节尺寸
- Android 根据屏幕大小设置字体
- word中的字体大小是excel中的多少?
- 根据字体多少使UILabel自动调节尺寸
- 根据设备分辨率更改根字体大小
- Android 根据屏幕大小设置字体
- UIWebView和WKWebView 改变HTML 图片尺寸 及 字体大小
- js改变文本字体大小及颜色,先放大后缩小,10次循环
- JS根据设备宽度设置根节点(html)font-size字体大小
- Android 根据屏幕大小设置字体
- UIWebView 控制页面 字体 大小
- 根据字体多少使UILabel自动调节尺寸
- IOS_UIWebView字体大小、字体颜色、背景色
- 1.根据字体多少使UILabel自动调节尺寸 2.跑马灯
- 根据字体多少使UILabel自动调节尺寸