UITextView: How to really disable editing?
First of all, you are using setter methods when you could just be using properties. Secondly, you are setting a whole bunch of unnecessary properties that are very close to the default. Here is a much simpler and perhaps what you intended with your code:
Objective-C
- (void)loadTextView1 {
UITextView *textView1 = [[UITextView alloc] initWithFrame:CGRectMake(15, 29, 290, 288)];
textView1.text = @"Example of non-editable UITextView";
textView1.backgroundColor = [UIColor clearColor];
textView1.editable = NO;
[self addSubView:textView1];
[textView1 release];
}
Swift
func loadTextView1() {
let textView1 = UITextView(frame: CGRect(x: 15, y: 29, width: 290, height: 288))
textView1.text = "Example of non-editable UITextView"
textView1.backgroundColor = .clear
textView1.isEditable = false
addSubView(textView1)
}
For Swift 3.0 and Swift 4.0:
textView.isEditable = false
You can use the property editable
textView.editable = NO;
Swift 2.0 Version
self.textView.editable = false
More details can be found in the apple UIKit Framework Reference.
Additional UITextView Attributes to consider:
- text
- attributedText
- font
- textColor
- editable
- allowsEditingTextAttributes
- dataDetectorTypes
- textAlignment
- typingAttributes
- linkTextAttributes
- textContainerInset