Search code examples
ioscore-text

How to make a reader like the kindle app?


I'd like to make a reader that behaves like Amazon's Kindle app. Specifically, I want to present a bunch of justified text in paragraphs, one column per page, and have it scroll between pages like the Kindle app does.

Let's assume I have the text in a simple format, like a text file per chapter, or even a string hard-coded in memory per chapter.

They're obviously using Core Text. Are they using a paged scroll view? Would that run in to memory problems for large books?


Solution

  • I ended up making something completely custom. It consists of 3 views, a left main and right view.

    The view controller renders the text on the main view using Core Text, and calculates the size of the text frames (and therefore the number of pages) for each page in the current chapter.

    If the user taps or drags right or left, the view controller will render one of the side views and let you drag it on. When you finish dragging or complete the tap action, it animates the pages into place, then swaps the main view with the one you dragged on.

    The advantage to this method over using a UICollectionView is that it's very expensive to calculate the exact contents that should be displayed on a given page in a deterministic way, as a table/collection view would require. This way allows me to render the text of any chapter, and go back or forward lazily without laying out the whole book at once.