26

I made this UITextView and everything is perfect except the fact that when the user taps it, the keyboard opens up. How can I disable that "editing(?)" option?
Here's the code:

- (void)loadAboutStable {
UITextView *aboutStable = [[UITextView alloc] init];
[aboutStable setText:@"Please check Your network connection"];
[self addSubview:aboutStable];}
James Webster
  • 31,873
  • 11
  • 70
  • 114
Peter V
  • 2,478
  • 6
  • 36
  • 54

9 Answers9

69

[aboutStable setUserInteractionEnabled:NO] should do it

and if you still need scrolling:

aboutStable.editable = NO;
James Webster
  • 31,873
  • 11
  • 70
  • 114
  • 1
    This will also prevent scrolling, which you may still want to allow. the solution by @Jacob prevents editing but allows scrolling. – Cowirrie Apr 09 '12 at 01:10
  • This does not allow scrolling.[textview setEditable:NO]; worked for me – pa12 Jul 10 '12 at 21:14
20
aboutStable.editable = NO;

should work

Jacob
  • 1,459
  • 2
  • 19
  • 32
6

You can do it with XIB too by UnCheck of the editable checkbox as given in below screen : enter image description here

and also do it by code :

textViewObject.editable = false
Alok
  • 24,880
  • 6
  • 40
  • 67
4
yourTextView.editable = NO;

It will make your text View not editable. It can be called from anywhere if you have made the property of you text view in .h file like this

@property (nonatomic, strong) UITextView *youTextView;
Jamon Holmgren
  • 23,738
  • 6
  • 59
  • 75
iOmi
  • 625
  • 10
  • 24
4

Select the UITextView in the storyboard

Choose the Property Inspector and under the Behavior section uncheck "Editable"

----Xcode version 5.0

1

SWIFT 2.0 & XCODE 7.0 example for solution provided by @James Webster

  1. In Main.storyboard (default), select your TextView
  2. Go to the Attribute Inspector of the TextView
  3. Uncheck "User Interaction Enabled"

IDE example

Patch92
  • 1,054
  • 11
  • 12
1

Swift 4 version:

aboutStable.isEditable = false
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Isaac Bosca
  • 1,588
  • 1
  • 15
  • 34
0

In Swift 2.0 it has to be false not NO.

theClues.selectable = false

I had a problem with making my clues appear in white letters unless I checked the selectable button on the storyboard for the textview. However, leaving "Selectable" checked and adding the line above works.

Mountain Man
  • 252
  • 2
  • 10
0

to really destroy any interactivity ;)

descriptionText.isSelectable = false;
descriptionText.isEditable = false;
barrylachapelle
  • 967
  • 4
  • 13
  • 34