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;

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

Yes, you can do it by using html tags.

NSString *stringToLoad = [NSString stringWithFormat:@"<html><center><font size=+5>%@</font></center></html>", myString];

Comments

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];

2 Comments

what does content men here ??
content is your myString which u'll get from file. edited answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.