如何真正禁用编辑

如何真正禁用编辑

本文介绍了UITextView:如何真正禁用编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的 UITextView 上禁用编辑.我尝试了 [aboutStable setUserInteractionEnabled: NO],但它导致页面无法访问.

I am trying to disable editing on my UITextView. I have tried [aboutStable setUserInteractionEnabled: NO], but it causes the page to not be accessible.

这是当前代码.

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

推荐答案

首先,当您可以使用属性时,您正在使用 setter 方法.其次,您正在设置一大堆非常接近默认值的不必要属性.这是一个更简单的代码,也许是您想要的代码:

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:

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

迅捷

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

这篇关于UITextView:如何真正禁用编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 04:19