Modification of Font Size and Font Style in UIWebView Control
- 2021-11-13 18:28:03
- OfStack
Modify the style of fonts in UIWebView controls:
NSString *htmlString = [NSString stringWithContentsOfFile:self.webPath encoding:NSUTF8StringEncoding error:nil];
UIFont *font = [UIFont systemFontOfSize:12];
NSString *newHtmlString = [NSString stringWithFormat:@"<font face='%@' >%@", font.fontName,htmlString];
[self.myWebView loadHTMLString:newHtmlString baseURL:[NSURL URLWithString:self.webPath]];
Where self. webPath is the path of the local web page.
Modify the font size in the UIWebView control:
NSString *str = @"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '60%'";
[self.myWebView stringByEvaluatingJavaScriptFromString:str];
You can modify the percentage as needed.