2 Replies Latest reply: Oct 28, 2009 5:13 AM by MiniRobinho
MiniRobinho Level 1 Level 1 (0 points)
Two questions about using a UIScrollView - you can't search text in it, and jump to the next use of the word and/or highlight it? And there's no other way to display scrollable text that can jump to a specific word when searched?

Secondly can you set the UIScrollView to scroll to a particular line or maybe a designated content rectangle (i.e. state the content area frame)?

Thanks

Macbook, Mac OS X (10.5.8)
  • RayNewbie Level 5 Level 5 (6,810 points)
    UIScrollView doesn't do any of the things you asked about, but UITextView does.
    MiniRobinho wrote:
    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!
    \- Ray
  • MiniRobinho Level 1 Level 1 (0 points)
    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. Simples