开发者

Displaying content at correct scale in UIWebView on iPad

开发者 https://www.devze.com 2023-01-15 11:38 出处:网络
I have a UIWebView set to scale to fit in an iPad app that gets its content from and NSString. If I turn off scale to fit the text is bigger, although would like it to be much bigger, but I lose the

I have a UIWebView set to scale to fit in an iPad app that gets its content from and NSString.

If I turn off scale to fit the text is bigger, although would like it to be much bigger, but I lose the zooming feature.

If I set scale to fit on the text is very small as it is obviously scaling the lot to fit the page...and I get zooming back.

How do I get it to allow me to zoom but also decide how large or how small I want the font to be upon firs开发者_C百科t displaying the content?

Thanks


Put this in the CSS of your HTML (or your local .css file), and when loaded on an iPad, the font will be twice the size of the iPhone. I just used it in a project and it worked like a charm.

@media all and (min-device-width: 481px) and (max-device-width: 1024px) {
        body { font-size: 200%; }   
    }

You can also do media queries for portrait / landscape and so on.


  NSString *webViewContent = [NSString stringWithFormat:@"<html> \n"
                                "<head> \n"
                                "<style type=\"text/css\"> \n"
                                "body {font-family: \"%@\"; font-size: %@;}\n"
                                "</style> \n"
                                "</head> \n"
                                "<body>%@</body> \n"
                                "</html>", @"helvetica", [NSNumber numberWithInt:kFieldFontSize], content];
//kFieldFontSize = 'specify your font size'

[yourWebVIew loadHTMLString:webViewContent baseURL:nil];

use the above method to change the font.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号