简体   繁体   English

如何在iOS中更改ePub Book的字体颜色和字体样式?

[英]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.

相关问题 iPhone epub阅读器如何以编程方式更改字体大小/颜色? - iphone epub reader how to change the font size/color programmatically? 如何更改titleForHeaderInSection的字体颜色? - How can i change the font color for titleForHeaderInSection? iPhone ePub Reader更改ePub中所有页面的字体,而不是当前的webview内容 - iPhone ePub Reader Change font of all pages in ePub book not current webview contents 如何更改UIBarButton项的字体颜色? - How can I change the font color of a UIBarButton item? NavigationBar如何标题字体颜色字体样式 - NavigationBar How to Title Font color font style 更改工具栏颜色和字体IOS 9 - change toollbar color and font IOS 9 iOS-如何为自定义字体设置后备字体? - iOS - How can I set a fallback font for my custom font? 如何更改 UISegmentedControl 的字体颜色 - How to change font color of UISegmentedControl iPhone iOS5 如何向用户显示字体类型、大小、颜色和 alignment 小部件? - iPhone iOS5 How can I present a font type, size, color and alignment widget to the user? 如何在UIWebView CGPDFDocumentRef中更改pdf文档的字体属性(大小,颜色,样式) - how to change the font properties(size, color,style) of the pdf document in UIWebView CGPDFDocumentRef
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM