【问题标题】:How can I change font color and font style of ePub Book in iOS?如何在 iOS 中更改 ePub Book 的字体颜色和字体样式?
【发布时间】:2012-05-30 10:04:39
【问题描述】:

我创建了支持 pdf 和 ePub 格式的图书应用程序。在该应用程序中,pdf 仅显示为图像,并且 ePub 在 webview 中打开,因为 EPUB 只是存储在带有 XML 清单的 zip 文件中的 XHTML。现在,我想更改 ePub 书页的字体样式和字体颜色。可能吗?如果可能的话,那么我该如何实现呢?我搜索了很多,但没有得到任何合适的解决方案。

【问题讨论】:

  • 你有办法在非移动浏览器中做 sam 吗? (例如 Mac Cocoa webview)
  • 表示你想为 mac webview 开发而不是为 iPhone 开发?
  • 对不起,我对 mac 开发一无所知。但可能只是 MAC 端开发的微小变化

标签: iphone objective-c ios ipad epub


【解决方案1】:

我找到了解决方案。 我已经创建了一个字符串并使用 Java 字符串进行评估

这是我写的:

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];

【讨论】:

  • 这里我以纵向模式将 epub 渲染到 uiwebview 中,它加载了内容,但在横向我需要显示两个页面视图,你有什么想法吗
  • 我正在使用与横向模式相同的工作。很快与您分享
  • 你是否集成了类似于 iBook 的 pagecurl,因为我也在这方面工作
  • 是的,我有很多搜索,但没有找到漂亮的解决方案。你有吗?
  • 你能把你的mailid发给我吗?我会分享那部分
猜你喜欢
  • 2011-11-22
  • 1970-01-01
  • 1970-01-01
  • 2014-02-03
  • 2020-12-01
  • 2016-10-12
  • 1970-01-01
  • 2013-10-10
  • 1970-01-01
相关资源
最近更新 更多