This discussion is archived
1225 Views 2 Replies Latest reply: Oct 28, 2009 5:13 AM by MiniRobinho
UIScrollView doesn't do any of the things you asked about, but UITextView does.
search text in it, and jump to the next use of the word and/or highlight it?
You can obtain the text at any time from the NSString* text property. So you can search for any substring and obtain its index range with NSString methods, then highlight that range and scroll it to visibility with UITextView methods. UISearchBar would normally be used to obtain the search key.
scroll to a particular line or maybe a designated content rectangle (i.e. state the content area frame)?
You could use scrollRangeToVisible: after finding the index of the target substring in the text. Apropos our recent discussion on pagination, there's no easy way to find the bounding rectangle of a substring (nor anyway to determine the substring inside a given rectangle) unless we have wrapped the text ourselves.
Hope that's what you were looking for!
\- RayMacBook, Mac OS X (10.5.5)
Thanks again Ray, that's exactly what I was looking for. I didn't know UITextView was scrollable, just by the name I just guessed that was the point of UIScrollView. Silly me If the UITextView is set to not editable, will it still allow me to highlight the words searched?
The scrolling to a line or content rectangle was a different question, it was actually back to the pagination thing again Basically I was thinking that if you work out the amount of pages that needs to be shown for a particular NSString, using that SO page code http://stackoverflow.com/questions/1435281/how-to-move-through-multiple-pages-of -text-using-paging then page 1 could be just UITextView with scrolling disabled, then when the user clicks next page you could scroll to a particular rectangle like
scroller.contentOffset = CGPointMake (0,460)
Then for page x it would be
scroller.contentOffset = CGPointMake (0,(460*x))
And then update a little page label at the bottom, which is x. And then when x == number of pages, disable next page button. SimplesMacbook, Mac OS X (10.5.8)