I want to load long text in TextViews of different Views. The text should be divided to pages when it reaches end of the textviews. And the next textview must start with the con
You can create a CTFramesetter and call CTFramesetterSuggestFrameSizeWithConstraints. You will then find the range of text that fits within a given CGSize. Then manipulate the Text in accordance to the range and you are done.
Reference - CoreText.
I had to do measurements of text in a UITextView a while ago for overlaying views on top of some words in a UITextView on iOS 5. With the UITextView changes for iOS 7 I no longer have to do this. The way I did measurement may be what you need to break up your text. I don't have a good working code to give so I will have to describe the algorithm as best I can remember it.
This algorithm does not work when there are variable line heights.
[substr sizeWithFont:font constrainedToSize:sizeConstraint lineBreakMode:NSLineBreakByWordWrapping]
where the size constraints in the width from step 1 and a very large height.Option 2 does work in iOS with the proper parameters.
NSAttributedString *attrStr = ... // your attributed string
CGFloat width = 300; // whatever your desired width is
CGRect rect = [attrStr boundingRectWithSize:CGSizeMake(width, 10000) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil];
Without the proper values for the options parameter you will get the wrong height.
got this answer from here
I did something like that using the library DTCoreText.
DTCoreText includes layout helpers with them was easy to cut the text in columns and create the different textviews. I created an example on github showing how can be done:
https://github.com/brovador/DTCoreTextColumnsExample
Hope it helps
How about assigning the total text to all of the text views. Then when ever we are moving from one text to another text view we just use the below function of the text view.
- (void)scrollRangeToVisible:(NSRange)range;
You would be deciding what that range should be initially, and then keep on altering it for every iteration until you reach end of string.
Use following method :
NSString *textEntered = [[[tvQuestion.text copy] autorelease] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
//Added for 450 character restriction
if([textEntered length] > 450) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Message" message:kMoreThan450CharactersForQuestion delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
[alertView release];
}