28

In a UITextView have a text which is for readonly and dont want any userinteraction at all means dont want text to be edited and even dont want keyboard to showup. I want to make UITextView scrollable.

Right now what happening is that it is not scrollable and the content is editable and keyboard shows up and bottom wall of the border is not showing. If anyone can help me with this issue. Will appreciate it so much.

Thanks in advance.

DShah
  • 9,768
  • 11
  • 71
  • 127
user1120133
  • 3,244
  • 3
  • 48
  • 90

5 Answers5

45

Set the editable / isEditable property to NO / false.

Swift 3, 4:

textView.isEditable = false

Swift 1, 2:

textView.editable = false

Objective-C:

textView.editable = NO;
Linus Unnebäck
  • 23,234
  • 15
  • 74
  • 89
Jason
  • 86,222
  • 15
  • 131
  • 146
12
textView.editable = NO;

It's mentioned in the documentation.

And about the scrolling; Your UITextView will scroll when the content size exceeds the frame size of your UITextView.

Community
  • 1
  • 1
Sid
  • 9,508
  • 5
  • 39
  • 60
  • self.textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 415)]; self.textView.textColor = [UIColor whiteColor]; self.textView.font = [UIFont fontWithName:@"Georgia-BoldItalic" size:16]; – user1120133 Jan 09 '12 at 17:37
  • 2
    That looks like a really large frame. I don't see the text you are putting in the textview but I can guess that your textView frame is larger than the content size (size of the text). At this point it would be best to attach a screenshot of what your textview looks like. – Sid Jan 09 '12 at 18:01
3
textview.editable = false // for swift language
textview.selectable = false //

// override textview delegates
func textViewShouldBeginEditing(textView: UITextView) -> Bool {
    return false
}
Bannings
  • 10,376
  • 7
  • 44
  • 54
2

you can also set the behavior through storyboard. just uncheck the 'editable' like the image below

enter image description here

sarah
  • 3,819
  • 4
  • 38
  • 80
0

Update Swift 3+

editable and selectable have been renamed to isEditable and isSelectable

textView.isEditable = false
textView.isSelectable = false

A Boolean value indicating whether the receiver is editable. The default value of this property is true.

 var isEditable: Bool { get set }

A Boolean value indicating whether the receiver is selectable. This property controls the ability of the user to select content and interact with URLs and text attachments. The default value is true.

 var isSelectable: Bool { get set }
Mick
  • 30,759
  • 16
  • 111
  • 130