开发者

Read database, put the text in two columns to fill them, and same the rest iPad

开发者 https://www.devze.com 2023-04-11 11:03 出处:网络
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 wha

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 neede开发者_JS百科d for each page and the text that left.

Can you help me doing that?

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号