MendyK
MendyK

Reputation: 1488

FlipView controller characters in different places

I have a flip view controller that flips (instead of the default scrolling) through text. I added a txt file to the project and (since it has 50,000 characters) used the "substringWithRange" method to create a substring for each page. I have a set number of characters in each page, but they display differently. I'd like to know how to get them to display exactly the same. meaning I (eventually) want the text to go to the end of the page, but when I try that, some text gets cut off.

Heres the code I'm using to substring the text

if (self.pageIndex == 1)//self.txt is the string that has the entire .txt file in it. For each page I'm substringing it.
{
    self.txt = [self.txt substringWithRange:NSMakeRange(0,1300)];
}
if (self.pageIndex == 2)
self.txt = [self.txt substringWithRange:NSMakeRange(1300,1300)];

Heres an example. Please let me know if you need any other info

page 1

enter image description here

page 2

enter image description here

they are ending at different physical locations even though I made them the exact same amount of characters

even with courier (fixed font, apparently), the text is still different for each page enter image description here enter image description here

Upvotes: 0

Views: 21

Answers (1)

rmaddy
rmaddy

Reputation: 318814

It's a proportional font. The width of 10 is is different than the width of 10 ms.

Proportional font:

iiiiiiiiii
mmmmmmmmmm

Fixed-width font:

iiiiiiiiii
mmmmmmmmmm

Either use a fixed-width font or find a way to extract the proper number of characters for each page based on the desired text length for the given font.

Update:

Even with a fixed width font, you are using word wrapping. Different length words mean each line is comprised of different numbers of letters.

You really only have two choices:

  1. Use a fixed width font and character wrapping. This is simple but it will be terrible for the user since words will be split on the middle.
  2. Use a regular font and word wrapping. But you will need to do more complicated and slower calculations to determine the proper length of text for each page to get end the same. And even then, it won't be exact since the last word length of each page may be a little different.

Upvotes: 1

Related Questions