Peter V
Peter V

Reputation: 2488

Making a UITextView not editable by the user

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];}

Upvotes: 27

Views: 34903

Answers (9)

Alok
Alok

Reputation: 25938

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

Upvotes: 7

barrylachapelle
barrylachapelle

Reputation: 987

to really destroy any interactivity ;)

descriptionText.isSelectable = false;
descriptionText.isEditable = false;

Upvotes: 0

Isaac Bosca
Isaac Bosca

Reputation: 1648

Swift 4 version:

aboutStable.isEditable = false

Upvotes: 1

Mountain Man
Mountain Man

Reputation: 242

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.

Upvotes: 0

iOmi
iOmi

Reputation: 635

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;

Upvotes: 4

Patch92
Patch92

Reputation: 1094

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

Upvotes: 1

user2911225
user2911225

Reputation: 41

Select the UITextView in the storyboard

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

----Xcode version 5.0

Upvotes: 4

James Webster
James Webster

Reputation: 32066

[aboutStable setUserInteractionEnabled:NO] should do it

and if you still need scrolling:

aboutStable.editable = NO;

Upvotes: 69

Jacob
Jacob

Reputation: 1459

aboutStable.editable = NO;

should work

Upvotes: 20

Related Questions