以下のコードを使用して、フォントサイズとテキストの配置の問題を修正しました。それがあなたに役立つことを願っています。
- (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];}