Reena
Reena

Reputation: 29

UIWebView HTML font size issue

I display HTML content in UIWebView in my one of the iPhone application.

Check below 2 images :

https://dl.dropboxusercontent.com/u/68104003/Screen%20Shot%202013-05-11%20at%2011.47.02%20AM.png https://dl.dropboxusercontent.com/u/68104003/Screen%20Shot%202013-05-11%20at%2011.47.28%20AM.png

I have used the same HTML code for both titles but it display the different font size on the screen.

Below is the HTML code i have used :

<span style="font-size:19px;"><strong><span style="font-family:times new roman,times,serif;">4.6&nbsp;&nbsp;Lorem Ipsum is simply</span></strong></span></br>

<span style="font-size:19px;"><strong><span style="font-family:times new roman,times,serif;">4.4&nbsp;&nbsp;Type and Scrambled</span></strong></span></br>

Please help.

Upvotes: 1

Views: 1966

Answers (3)

uzumaki
uzumaki

Reputation: 21

    <meta name=\"viewport\" content=\"initial-scale=5.0\" /> 

added this to the html string worked for me change the initial scale as required

Upvotes: 2

Ashini
Ashini

Reputation: 492

i used below code to fix font size and text alignment problem. Hope it will help for you.

- (void)viewDidLoad
{   [super viewDidLoad];
currentTextSize = 100;
webview.userInteractionEnabled=YES;
webview.delegate=self;
webview.scalesPageToFit=YES;
webview.scrollView.pagingEnabled = YES;}

-(void)webViewDidFinishLoad:(UIWebView *)webView{
NSString *varMySheet = @"var mySheet = document.styleSheets[0];";
NSString *addCSSRule =  @"function addCSSRule(selector, newRule) {"
"if (mySheet.addRule) {"
"mySheet.addRule(selector, newRule);"                               // For Internet Explorer
"} else {"
"ruleIndex = mySheet.cssRules.length;"
"mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);"   // For Firefox, Chrome, etc.
"}"
"}";
 NSString *insertRule2 = [NSString stringWithFormat:@"addCSSRule('p', 'text-align: justify;')"];
NSString *insertRule1 = [NSString stringWithFormat:@"addCSSRule('html', 'padding: 0px; height: %fpx; -webkit-column-gap: 0px;')", webView.frame.size.height];

NSString *setTextSizeRule = [NSString stringWithFormat:@"addCSSRule('body', '-webkit-text-size-adjust: %d%%;')", currentTextSize];
 [webView stringByEvaluatingJavaScriptFromString:varMySheet];
[webView stringByEvaluatingJavaScriptFromString:addCSSRule];
[webView stringByEvaluatingJavaScriptFromString:insertRule1];
[webView stringByEvaluatingJavaScriptFromString:insertRule2];
[webView stringByEvaluatingJavaScriptFromString:setTextSizeRule];}

Upvotes: 1

Caleb
Caleb

Reputation: 124997

UIWebView supports zooming, and that naturally affects the size of the type. It's likely that when you saw the larger type, you were just zoomed in further, perhaps because the widths of the two pages is different.

Upvotes: 0

Related Questions