How to add CTFrame to UIViewController?

194 views Asked by At

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.

1

There are 1 answers

4
danh On

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.