[英]How can I change font color and font style of ePub Book in iOS?
I have created app of books which supports pdf and ePub format. 我创建了支持pdf和ePub格式的书籍应用程序。 In that app, pdf is just shown as an image and ePub open in webview because EPUB is just XHTML stored in a zipfile with an XML manifest.
在该应用程序中,pdf仅显示为图像,ePub在webview中打开,因为EPUB只是存储在带有XML清单的zipfile中的XHTML。 Now, I want to change the font style and font color of ePub book pages.
现在,我想更改ePub书页的字体样式和字体颜色 。 Is it possible?
可能吗? If possible, then how can I achieve this?
如果可能的话,我该如何实现这一目标? I have searched a lot, but did not get any proper solution.
我搜索了很多,但没有得到任何适当的解决方案。
I have found the solution. 我找到了解决方案。 I have make a string and evaluate using Java string
我创建了一个字符串并使用Java字符串进行评估
This is what I have written: 这就是我写的:
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];
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;')"];
// this is what change the text style
NSString *insertRule3 = [NSString stringWithFormat:@"addCSSRule('html, body, div, p, span, a', 'font-family: arial;')"];
NSString *changeColor = [NSString stringWithFormat:@"addCSSRule('html, body, div, p, span, a', 'color: #1122CC;')"];
[webView stringByEvaluatingJavaScriptFromString:varMySheet];
[webView stringByEvaluatingJavaScriptFromString:addCSSRule];
[webView stringByEvaluatingJavaScriptFromString:insertRule1];
[webView stringByEvaluatingJavaScriptFromString:insertRule2];
[webView stringByEvaluatingJavaScriptFromString:setTextSizeRule];
[webView stringByEvaluatingJavaScriptFromString:setHighlightColorRule];
[webView stringByEvaluatingJavaScriptFromString:insertRule3];
[webView stringByEvaluatingJavaScriptFromString:changeColor];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.