ios 使用户无法编辑 UITextView

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7323115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:24:40  来源:igfitidea点击:

Making a UITextView not editable by the user

iosobjective-cuitextview

提问by Peter V

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:

我制作了这个 UITextView 并且一切都很完美,除了当用户点击它时,键盘会打开。如何禁用“编辑(?)”选项?
这是代码:

- (void)loadAboutStable {
UITextView *aboutStable = [[UITextView alloc] init];
[aboutStable setText:@"Please check Your network connection"];
[self addSubview:aboutStable];}

回答by James Webster

[aboutStable setUserInteractionEnabled:NO]should do it

[aboutStable setUserInteractionEnabled:NO]应该做

and if you still need scrolling:

如果您仍然需要滚动:

aboutStable.editable = NO;

回答by Jacob

aboutStable.editable = NO;

should work

应该管用

回答by Alok

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

您也可以通过取消选中可编辑复选框来使用 XIB 执行此操作,如下面的屏幕所示: 在此处输入图片说明

and also do it by code :

也可以通过代码来完成:

textViewObject.editable = false

回答by iOmi

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

它会使您的文本视图不可编辑。如果您在 .h 文件中设置了文本视图的属性,则可以从任何地方调用它

@property (nonatomic, strong) UITextView *youTextView;

回答by user2911225

Select the UITextViewin the storyboard

故事板中选择UITextView

Choose the Property Inspectorand under the Behaviorsection uncheck "Editable"

选择Property Inspector并在Behavior部分下取消选中“ Editable

----Xcode version 5.0

----Xcode 5.0 版本

回答by Patch92

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

@James Webster 提供的解决方案的 SWIFT 2.0 和 XCODE 7.0 示例

  1. In Main.storyboard (default), select your TextView
  2. Go to the Attribute Inspector of the TextView
  3. Uncheck "User Interaction Enabled"
  1. 在 Main.storyboard(默认)中,选择您的 TextView
  2. 转到 TextView 的属性检查器
  3. 取消选中“启用用户交互”

IDE example

IDE示例

回答by Isaac Bosca

Swift 4 version:

斯威夫特 4 版本:

aboutStable.isEditable = false

回答by barrylachapelle

to really destroy any interactivity ;)

真正破坏任何交互性;)

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

回答by Mountain Man

In Swift 2.0 it has to be false not NO.

在 Swift 2.0 中,它必须是 false 而不是 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.

我在让我的线索以白色字母显示时遇到了问题,除非我检查了故事板上的文本视图的可选按钮。但是,选中“Selectable”并添加上面的行是可行的。