0

このコードを使用して、ipad で epub ブックを表示しています。問題は、左側に余白を表示したいことです。..ここでマージンを変更しようとしましたが、うまくいきません。

 - (void)webViewDidFinishLoad:(UIWebView *)theWebView{

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 *insertRule1 = [NSString stringWithFormat:@"addCSSRule('html', 'padding: 0px; height: %fpx; -webkit-column-gap: 0px; -webkit-column-width: %fpx;')", webView.frame.size.height, webView.frame.size.width/2];
NSString *insertRule2 = [NSString stringWithFormat:@"addCSSRule('p', 'text-align: justify;')"];
NSString *setTextSizeRule = [NSString stringWithFormat:@"addCSSRule('body', '-webkit-text-size-adjust: %d%%;')", currentTextSize];
NSString *setHighlightColorRule = [NSString stringWithFormat:@"addCSSRule('highlight', 'background-color: yellow;')"];

NSString *setImageRule = [NSString stringWithFormat:@"addCSSRule('img', 'max-width: %fpx; height:auto;')", webView.frame.size.width/2 *0.75];
NSString *setFontRule = [NSString stringWithFormat:@"addCSSRule('body', 'font-family: Arial;' , 'font-name: Arial-BoldItalicMT;')"];

[webView stringByEvaluatingJavaScriptFromString:setFontRule];

[webView stringByEvaluatingJavaScriptFromString:setImageRule];

[webView stringByEvaluatingJavaScriptFromString:varMySheet];

[webView stringByEvaluatingJavaScriptFromString:addCSSRule];

[webView stringByEvaluatingJavaScriptFromString:insertRule1];

[webView stringByEvaluatingJavaScriptFromString:insertRule2];

[webView stringByEvaluatingJavaScriptFromString:setTextSizeRule];

[webView stringByEvaluatingJavaScriptFromString:setHighlightColorRule];


if(currentSearchResult!=nil){
//  NSLog(@"Highlighting %@", currentSearchResult.originatingQuery);
    [webView highlightAllOccurencesOfString:currentSearchResult.originatingQuery];
}


int totalWidth = [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollWidth"] intValue];
pagesInCurrentSpineCount = (int)((float)totalWidth/(webView.bounds.size.width/2));

NSLog(@"pagesInCurrentSpineCount is %d",pagesInCurrentSpineCount);

[self gotoPageInCurrentSpine:currentPageInSpineIndex];

}

4

0 に答える 0