使 UITextView 无法被用户编辑

发布于 2024-12-03 03:00:15 字数 272 浏览 1 评论 0原文

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

一身仙ぐ女味 2024-12-10 03:00:15

[aboutStable setUserInteractionEnabled:NO] 应该这样做

,如果您仍然需要滚动:

aboutStable.editable = NO;

[aboutStable setUserInteractionEnabled:NO] should do it

and if you still need scrolling:

aboutStable.editable = NO;
猥琐帝 2024-12-10 03:00:15
aboutStable.editable = NO;

应该有效

aboutStable.editable = NO;

should work

成熟的代价 2024-12-10 03:00:15

您也可以通过取消选中可编辑复选框来使用 XIB 来完成此操作,如下屏幕所示:
输入图片此处描述

也可以通过代码完成:

textViewObject.editable = false

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
无戏配角 2024-12-10 03:00:15

故事板中选择UITextView

选择属性检查器,然后在行为部分下取消选中“可编辑< /strong>"

----Xcode 版本 5.0

Select the UITextView in the storyboard

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

----Xcode version 5.0

握住你手 2024-12-10 03:00:15
yourTextView.editable = NO;

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

@property (nonatomic, strong) UITextView *youTextView;
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;
孤星 2024-12-10 03:00:15

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

  1. 在 Main.storyboard(默认)中,选择您的 TextView
  2. 转到 TextView 的属性检查器
  3. 取消选中“用户交互已启用”

IDE 示例

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

彩虹直至黑白 2024-12-10 03:00:15

斯威夫特 4 版本:

aboutStable.isEditable = false

Swift 4 version:

aboutStable.isEditable = false
屋檐 2024-12-10 03:00:15

在 Swift 2.0 中它必须是 false 而不是 NO。

theClues.selectable = false

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

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.

表情可笑 2024-12-10 03:00:15

真正破坏任何交互性;)

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

to really destroy any interactivity ;)

descriptionText.isSelectable = false;
descriptionText.isEditable = false;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文