I have given a large text to display in different text views. So i have set the whole text content in an NSTextContainer
.Then added a NSLayoutManager
. Created NSTextContainers for different UITextViews
. I got continuous text in different TextViews
. But i cant limit the no of textviews using a condition.
My problem is i want to create textviews accroding to the content. And the content may vary.I tried to create a condition bw whole text content & textview's content. But even though each contains different text, all textview.text length
returns the same value as the length of the entire text content !!!!
Here is the code>>
-(void)paginate:(NSString*)chapterData WithSize:(CGRect)frame
{
int stringLength,totalTextViewsTextLength;
totalTextViewsTextLength=0;
NSString* htmlString = [NSString stringWithContentsOfFile:chapterData encoding:NSUTF8StringEncoding error:nil];
NSAttributedString *temp=[[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]} documentAttributes:nil error:nil];
NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:temp];
NSLayoutManager *textLayout = [[NSLayoutManager alloc] init];
[textStorage addLayoutManager:textLayout];
stringLength=[temp length];
while (totalTextViewsTextLength<stringLength) // checks whether all the content has been added to textview or not
{
NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:frame.size];
[textLayout addTextContainer:textContainer];
// textContainer.lin
UITextView *textView=[[UITextView alloc]initWithFrame:frame textContainer:textContainer];
textView.tag=textviewCount;
// Store textviews in array
[pagedData addObject:textView];
totalTextViewsTextLength+=[textView.text length];
textviewCount++;
}
}
What i need is to get the length of text displayed in each textview(that contains different textcontainers ) ??????