views:

60

answers:

1

I want to create a text display area (either UILabel or UITextView) in my iPhone app which (1) allows scrolling and (2) does not allow selection. I have tried the following techniques unsuccessfully:

  1. Basic UILabel: Didn't allow scrolling, and clipped text to the bottom of UILabel space on screen.
  2. Giant UILabel within a UIScrollView: the UILabel kept placing the text (vertically) at the center of the giant UILabel, so it often was outside of my UIScrollView.
  3. UITextView: So far this approach has worked the best, because it scrolls and does not clip the text. I can even subclass UITextView to enable resizing the text to fit within the textview, and passing any touch events to the superview to detect taps & swipes. But, when the user taps and holds on the text itself, the text selection interface appears. I am not interested in this interface and it actually is distracting from the user's experience. I have tried to subclass canPerformAction:withSender:, but apparently this function is called after the tap event--not before it.

Does anyone know how to disable the text selection interface in UITextView, without also disabling scrolling?

A: 

Take option number 2, but set the numberOfLines property on your UILabel to 0. This will set the number of lines to 'unlimited' and prevent the vertical centring of the text.

Don't forget to set the lineBreakMode property to UILineBreakModeWordWrap so that your text doesn't run off the side of the UILabel.

Jasarien
This worked for me -- but UIScrollView is tricky. I still needed to dynamically change the size of each UILabel so that the text appeared at the top.
Jason