How to add CTFrame to UIViewController?

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.


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.

链接地址: http://www.djcxy.com/p/81912.html

上一篇: OS X El Capitan / macOS Sierra / macOS High Sierra

下一篇: 如何添加CTFrame到UIViewController?