views:

2868

answers:

4

hi any one say , how to increase or decrease the UIWebview font size, not using scalePageToFit:NO;

+8  A: 

There is currently no exposed way to directly manipulate the DOM in a UIWebView, nor any convenience methods for handling things like font sizes. I suggest filing Radars.

Having said that. you can modify the font size by changing the CSS, like any other webpage. If that is not possible (you don't control the content) you can write a small javascript function to change the CSS properties in the pages DOM, and execute it by calling:

- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script;
Louis Gerbarg
A: 

I do want to increase the font size of UIWebView content. Am not clear about the java script given above. could you explain this more?

thanks in advance

+8  A: 

I have 2 buttons - A- and A+

@interface
NSUInteger textFontSize;

- (IBAction)changeTextFontSize:(id)sender
{
    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];
    [web stringByEvaluatingJavaScriptFromString:jsString];
    [jsString release];
}
Slim
Be sure to set `textFontSize` to an initial value (presumably 100) before calling this.
zekel
A: 

You could also disable the buttons when they're at their respective limits. Add the following Slim's method, and you have to add IBOutlets for both buttons. (You could do it without IBOutlets if you really wanted to, but I think this is really clear.)

MyTextSizeMin = 50;
MyTextSizeMax = 100;

// disable buttons when they're out of the range.
BOOL smallerEnabled = textFontSize > MyTextSizeMin;
BOOL biggerEnabled = textFontSize < MyTextSizeMax;
[textSmallerButton setEnabled:smallerEnabled];
[textBiggerButton setEnabled:biggerEnabled];
zekel