I've got the code below working with IBActions on two buttons that decrease/increase
text font size in a UIWebView by following the instructions here.
Currently clicking either button causes the font size to decrease to the smallest possible size instead of incrementing up or down from the current size.
However, I have been unable to work out how to set an initial value for text font size which should fix the problem.
I've tried adding textFontSize = 100;
but this only allows the text to be resized one step (-5 or +5)
up or down. This has been irritating me for days. Any help much appreciated.
- (IBAction)changeTextFontSize:(id)sender;
//textFontSize = 100;
{
switch ([sender tag]) {
case 1: // A-
textFontSize = (textFontSize > 50) ? textFontSize -5 : textFontSize;
break;
case 2: // A+
textFontSize = (textFontSize < 160) ? textFontSize +5 : textFontSize;
break;
}
NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'",
textFontSize];
[webView stringByEvaluatingJavaScriptFromString:jsString];
[jsString release];
}