1

I have text file with some random text and i want to display it in webview with increased font,my question is can i change the font size. here is my code i have implemented.

NSString * myString = [NSString stringWithContentsOfFile:_urlPath encoding:NSUTF8StringEncoding error:nil];

[self.webView loadHTMLString:htmlString baseURL:nil];
[self.webView setScalesPageToFit:YES];
self.webView.autoresizesSubviews = YES;
vaibhav
  • 117
  • 2
  • 13

4 Answers4

1

You have to know the exact structure of your html string and you would need to modify the html string to change the font and font size. Add/Modify html tags around required text in order to change font and/or font size.

Use NSMutableString instead of NSString and then modify your string according to your requirement.

Salman Zaidi
  • 9,342
  • 12
  • 44
  • 61
0

Yes, you can do it by using html tags.

NSString *stringToLoad = [NSString stringWithFormat:@"<html><center><font size=+5>%@</font></center></html>", myString];
kabarga
  • 803
  • 6
  • 11
0

You need to convert your string to valid html string and then set font-family for html string:

NSString *myDescriptionHTML = [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>", @"HelveticaNeue", [NSNumber numberWithInt:kFieldFontSize], myString];
Kampai
  • 22,848
  • 21
  • 95
  • 95
0

Take a look at this question how to increase font size in UIWebView You could do it with a javascript command

Community
  • 1
  • 1
TMob
  • 1,278
  • 1
  • 13
  • 33