Question

after search a lot, I couldn't find an answer to my problem.

I want to build an app for iPad like a book, with two pages, with one column each.

After read some text from a database, I want to fulfill the two pages (with the right quantity of text), and save whats left to the next page. I will display some images between the text, and I need to make the text and image to fit in each page.

I'm thinking in use a UIWebView to hold the text.

My problem it's calculate the amount of text needed for each page and the text that left.

Can you help me doing that?

Thanks

Cumps

EDIT:

I will display some images between the text, and I need to make the text and image to fit in each page.

Was it helpful?

Solution

UIWebView is the wrong UI element to use if you just want to display text. You should know that loading a UIWebView takes long and eats up a lot of memory. This is a job for UITextView.

To calculate the text that will fit on a page, you will have to use the methods that UIKit adds to NSString. Here is the documentation. These help you to calculate the size a string will be when rendered with a certain font and certain line break mode.

CGSize renderedTextSize = [myString sizeWithFont:myFont forWidth:myTextView.frame.size.width lineBreakMode:UILineBreakModeWordWrap];

You could write a method that would use these methods calculate a substring of the text that will fit on your current "page" (UITextView). Then, for the next "page", start from where you left off on the last page and add text to that string until it fits perfectly in your text view (maybe you add words until it gets too big to fit, then take out the last word and return that substring).

Something like that should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top