UITextView: How to really disable editing?

ios, objective-c, uitextview

Solution

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)
}

Problem

I am trying to disable editing on my `UITextView`. I have tried `[aboutStable setUserInteractionEnabled: NO]`, but it causes the page to not be accessible. Here is the current code. ``` - (void)loadTextView1 { UITextView *textView1 = [[UITextView alloc] init]; [textView1 setFont:[UIFont fontWithName:@"Helvetica" size:14]]; [textView1 setText:@"Example of editable UITextView"]; [textView1 setTextColor:[UIColor blackColor]]; [textView1 setBackgroundColor:[UIColor clearColor]]; [textView1 setTextAlignment:UITextAlignmentLeft]; [textView1 setFrame:CGRectMake(15, 29, 290, 288)]; [self addSubview:textView1]; [textView1 release]; } ```

Original source