The way I would do it is to compute all the sizes of each paragraph. With sizeWithFont:constrainedToSize:lineBreakMode.
Up vote 11 down vote favorite 3 share g+ share fb share tw.
For example I may need to show next paragraph, then I want to find the current visible text range and use it to calculate the appropriate range and use scrollRangeToVisible: to scroll the text view iphone ios uiscrollview uitextview link|improve this question asked May 20 '11 at 5:26xlc0212917310 95% accept rate.
The way I would do it is to compute all the sizes of each paragraph. With sizeWithFont:constrainedToSize:lineBreakMode: you will then be able to work out which paragraph is visible, from the textView contentOffset. To scroll, don't use scrollRangeToVisible, just use setContentOffset: The CGPoint y parameter for this should either be the sum of all the height sizes to the next paragraph, or just add the textView.frame.size.
Height, if that is closer than the beginning of the next paragraph. This make sense? In answer to comment requst code bellow (untested): CGFloat paragraphOffsetMAX_PARAGRAPHS; CGSize constraint = CGSizeMake(widthOfTextView, 999999 /*arbitrarily large number*/); NSInteger paragraphNo = 0; CGFloat offset = 0; for (NSString* paragraph in paragraphs) { paragraphOffsetparagraphNo++ = offset; CGSize paragraphSize = paragraph sizeWithFont:textView.
Font constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap; offset += paragraphSize. Height; } // find visible paragraph NSInteger visibleParagraph = 0; while (paragraphOffsetvisibleParagraph.
– xlc0212 May 24 '11 at 11:56 added code above. FYI paragraphs is an NSArray of the paragraph strings – Nick H247 May 25 '11 at 11:42 1 Note that you can replace the 9999999 by FLT_MAX (default iPhone variable for a large value) – Niko Dec 14 '11 at 22:11.
One option you have is to use a UIWebView instead of a UITextView. You can then use anchors and javascript to scroll to the appropriate places in the text. You can probably insert the anchors programmatically at the start of each paragraph to make this easier.
Also UIWebView may be harder to deal with than UITextView – xlc0212 May 24 '11 at 11:59 @xlc0212: If you don't need editing, using a UIWebview will be much easier (and probably faster) than computing the text size of a UITextView every time you need to scroll. Just look up what 'html anchors' are - it's nothing complex. – roop Jun 17 '11 at 6:33.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.