3

I've had a good look around and I can't seem to find a good answer for this coding quandary!

I'm laying out pages in an eBook style app for iOS (Swift 3), and I'm trying to pre-calculate how many pages each chapter will need. The two main problems I'm having to tackle are:

  • The page can be viewed in a two / three column layout
  • The user can adjust the font size (resulting in more/less pages per chapter)

The tutorials and guides I've reviewed to achieve multi-page columnar layouts seem to require you to actually perform the laying-out of text in the UITextView before you can calculate how much text was used.

My ideal scenario would be a means to say 'I have a font of X size and this CGRect... how much text will fit inside this frame?', but without requiring me to perform the actual rendering of said text into the frame before the calculation is made (as you would using something like UITextView's characterRange(at:...)).

Is there any way to accomplish this? Am I chasing a solution for an unsolvable problem?

Thanks for any assistance that can be offered :o)

  • fill CGRect or textField? Are you using autolayouts? – Saranjith Jul 20 '17 at 08:49
  • Please [edit] your question to show [the code you have so far](http://whathaveyoutried.com). You should include at least an outline (but preferably a [mcve]) of the code that you are having problems with, then we can try to help with the specific problem. You should also read [ask]. – Toby Speight Jul 20 '17 at 08:53
  • The layouts will be made using UITextViews (so, one UITextView per column using an NSTextStorage instance with multiple NSTextContainers), but the sizes of these (laid out using Autolayout) can be arbitrary, hence the need to pre-calculate the text quantity :) –  Jul 20 '17 at 08:59

0 Answers0