电子阅读器式分页
我正在从 XML 文件中获取文本数据,并希望它在 iPad 上的 UIWebView
内以类似书页的格式显示。 XML 文件来自 .epub
,每个文件都包含一本书的一个章节,仅由 p 标签划分。
我想根据 UIWebView(整个 iPad 屏幕)的大小以及用户选择的字体大小,将这些文件动态分页到类似书本的页面中。我目前正在将带有相关 css 的空白 html 页面加载到 UIWebView
中,根据 XML 中的字符数作为字符串抓取段落,并使用 StringByEvaluatingJavaScriptFromString
将它们打印到 html 中和innerHTML 属性。
显然,按字符数执行此操作会创建间距不正确、格式奇怪的页面,但我不确定如何对文本进行“分页”。
我想做的是类似于 iPad 上的应用程序“eReader”:http://www.ereader.com/ 。他们似乎将单个文件动态分解为页面,并将其加载到 UIWebView 中。这是怎么做到的?
I am grabbing text data from XML files, and want it to display in book page-like format inside a UIWebView
on iPad. The XML files are coming out of a .epub
, and each one contains a single chapter of a book, divided up only by p tags.
I want to dynamically paginate these files into book-like pages based on the size of the UIWebView
, which is a full iPad screen, as well as by user-selected font size. I am currently loading a blank html page with related css into a UIWebView
, grabbing paragraphs based on number of characters as Strings from the XML, and printing these into the html using StringByEvaluatingJavaScriptFromString
and the innerHTML property.
Obviously, doing this by number of characters creates improperly spaced, oddly formatted pages, but I'm not sure how else to "paginate" the text.
What I am looking to do is something akin to the app "eReader" on iPad:http://www.ereader.com/. They seem to be breaking a single file up into pages dynamically, and loading it into UIWebView
s. How is this done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
大多数基于
UIWebView
的 EPUB 阅读器仅使用 CSS3 列对文档进行分页。您可以在 http://www.quirksmode.org/css/multicolumn.html< 中查看此操作的实际情况/a>
基本思想是对文档进行“分栏”,然后水平滚动以显示特定页面。
在为 iPhone 和 iPad 上的一款流行的(加拿大)电子阅读器应用程序完成此操作后,我可以告诉您,该技术有效,但远非理想。
Most EPUB readers that are based on
UIWebView
simply use CSS3 Columns to paginate the document.You can see this in action at http://www.quirksmode.org/css/multicolumn.html
The basic idea is that you 'columnize' the document and then scroll horizontally through it to show a specific page.
Having done this for one popular (Canadian) eReader application on the iPhone and iPad, I can tell you that the technique works but that it is far from ideal.
代码已经做好了。它被称为 epubjs。它是仅 Javascript 的 epub 阅读器。
The code is already made. It is called epubjs. It is Javascript only epub reader.
将 UITextView 与 PageviewController 结合使用。 (如果有的话,请在其中指出您的疑问)
Use UITextView with PageviewController . (specify your doubts in it , if any )