您的位置:首页 > 移动开发

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事件;
获取文本内容的高度,获取上一次的高度值,重新设定高度值。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: