I am trying to let the user resize the text of the given web page. I am using Swift in Xcode 6. HTML file:
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
My first paragraph.
</body>
</html>
and here is the swift function I am calling to try to change the size:
func changeWebViewFontSize(decOrInc: Int, webView: UIWebView)
{
//1 = decreace
//2 = increace
var textFontSizeTemp = defaults.objectForKey("textFontSize") as Int
switch decOrInc
{
case 1: //when decrease
defaults.setObject(textFontSizeTemp - 1, forKey: "textFontSize")
case 2: //when increase
defaults.setObject(textFontSizeTemp + 50, forKey: "textFontSize")
default:
break
}
var jsString = "document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust=\(textFontSize)"
//var jsString = "alert('test')"
webView.stringByEvaluatingJavaScriptFromString(jsString)
}
I know that the javascript is being run because when I ran an alert() function in the javascript, it worked. Please help me find out what is wrong with my code!