2

I need to have selectable text within a UIScrollView. As I understand it, the preferred way to make selectable text on the iPhone is to put it in a UITextView. However, that inherits from UIScrollView, and there are issues with putting one UIScrollView within another. For starters, the outer scrollview doesn't scroll anymore, and the text in the inner UITextView still isn't selectable.

What's the preferred way of getting selectable text into a UIScrollView?

baudot
  • 1,618
  • 20
  • 33

3 Answers3

1

I would still use a textview, but size it so that all of your text fits without it having to scroll. This then goes inside the scrollview which has it's content size set to at least that of the textview.

James P
  • 4,786
  • 2
  • 35
  • 52
  • That's akin to what I'm already doing, and the bug is still implicit. The textview is already sized to not need to scroll, ever. The outer scrollview is larger, to allow all the scrolling to happen there. – baudot Jan 06 '11 at 17:02
  • I just did a quick test and it seems to work, as long as the content size of the scrollview is bigger than its frame it scrolls fine and the textview is still editable. – James P Jan 06 '11 at 17:18
  • Have you tried setting scrollEnabled to NO for the embedded UITextView? As it inherits from UIScrollView, it should also have this property. – omz Jan 16 '11 at 07:08
  • In the end, I found that the scrollview sizing was what was failing - there was a bug keeping the view too small. Your first answer was right all along. – baudot Jan 16 '11 at 09:28
0

I asked and answered a question today related to UIScrollView subclasses inside each other that may be relevant:

UIPickerView inside UITableView.tableFooterView doesn't receive drag touches

This isn't a "how to build this" answer so much as a "how to hack it so what you think it ought to do becomes possible".

Community
  • 1
  • 1
Dan Ray
  • 21,623
  • 6
  • 63
  • 87
0

You can get more control over scrolling by doing a custom implementation of the scrollToRectVisible: animated: method, and also by setting scrollEnabled. A caution about scrollEnabled though -- setting it to NO does not turn off all scrolls! So you may want to have your own scrollingAllowed variable and check its value in your scrollToRectVisible: animated: method.

William Jockusch
  • 26,513
  • 49
  • 182
  • 323