使 UITextView 无法被用户编辑
我制作了这个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
[aboutStable setUserInteractionEnabled:NO]
应该这样做,如果您仍然需要滚动:
[aboutStable setUserInteractionEnabled:NO]
should do itand if you still need scrolling:
应该有效
should work
您也可以通过取消选中可编辑复选框来使用 XIB 来完成此操作,如下屏幕所示:
也可以通过代码完成:
You can do it with XIB too by UnCheck of the editable checkbox as given in below screen :
and also do it by code :
在故事板中选择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
它将使您的文本视图不可编辑。如果您在 .h 文件中设置了文本视图的属性,则可以从任何地方调用它
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
SWIFT 2.0 和 SWIFT 2.0 @James Webster 提供的解决方案的 XCODE 7.0 示例
SWIFT 2.0 & XCODE 7.0 example for solution provided by @James Webster
斯威夫特 4 版本:
Swift 4 version:
在 Swift 2.0 中它必须是 false 而不是 NO。
我在让线索以白色字母显示时遇到了问题,除非我检查了故事板上文本视图的可选按钮。但是,选中“Selectable”并添加上面的行是可行的。
In Swift 2.0 it has to be false not NO.
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.
真正破坏任何交互性;)
to really destroy any interactivity ;)