0

The goal is to format and show text as like as iBooks style pages. For this I take UIPageViewController, specify transition for needed animation and generate UIViewController collection and etc. To show text I place UITextView into each UIViewController of collection.

And to split text for pages automatically I have made my own procedure with:

[NSString sizeWithFont:...].

Thanks for the info from here - How does the iBooks App format the text on separate pages?

Everything is working but not so fine as I wish. NSString is not very convenient and UITextView shows text without good formatting. The splitting is not good enought too =)

Additionally I have tried splitting with Core Text. The approach is showed here - How to split long NSString into pages

It even works. Core Text splits well and it has many other good features. But! I couldn't use the values of splitted by Core Text text with UITextView. To show splitted by Core Text pages I must use Core Text techniques.

The quesion is: How to create a CTFrame and add/draw it for each UIViewController of collection for UIPageController?

I suspect that it is just impossible. If so, please suggest any idea to realize needed features.

And please excuse me for my question, I am new for iOS programming.

Community
  • 1
  • 1
RomanVD
  • 25
  • 1
  • 2
  • 7

1 Answers1

0

I haven't done this, but it looks to me like you can get the fitted string range from the CTFrame.

CTFrameRef ctFrameRef = // get this from CTFrameSetter
CFRange cfRange = CTFrameGetVisibleStringRange(ctFrameRef);
NSRange range = NSMakeRange(cfRange.location, cfRange.length);

Then range can be used to carve up the original string.

danh
  • 62,181
  • 10
  • 95
  • 136
  • If I understand you right, you suggest to convert resulted CoreText ranges to NSString ranges? – RomanVD Oct 08 '13 at 19:08
  • Yes, then you can examine the end of NSString substringWithRange: to see where the page break is. – danh Oct 08 '13 at 20:31
  • And what to do if it is large? Start to substruct word by word from the end? =) I will try to, at least to compare. Thanks for the idea. But what about adding natural CTFrame to UIViewController? Does anybody know the answer? – RomanVD Oct 08 '13 at 21:22
  • I have tried... CTFramesetterSuggestFrameSizeWithConstraints provides really uncompatible with UITextView result. – RomanVD Oct 09 '13 at 22:00