如何使 UITextView 不可编辑并且不希望键盘显示

发布于 2024-12-26 01:50:37 字数 174 浏览 3 评论 0原文

UITextView 中有一个只读文本,根本不需要任何用户交互,意味着不希望编辑文本,甚至不希望显示键盘。我想让 UITextView 可滚动。

现在发生的情况是它不可滚动,内容可编辑,键盘显示,但边框的底墙不显示。如果有人可以帮助我解决这个问题。会非常感激。

提前致谢。

In a UITextView have a text which is for readonly and dont want any userinteraction at all means dont want text to be edited and even dont want keyboard to showup. I want to make UITextView scrollable.

Right now what happening is that it is not scrollable and the content is editable and keyboard shows up and bottom wall of the border is not showing. If anyone can help me with this issue. Will appreciate it so much.

Thanks in advance.

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

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

发布评论

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

评论(5

∞觅青森が 2025-01-02 01:50:37

设置 可编辑 / isEditable 属性为 NO / false

Swift 3、4:

textView.isEditable = false

Swift 1、2:

textView.editable = false

Objective-C:

textView.editable = NO;

Set the editable / isEditable property to NO / false.

Swift 3, 4:

textView.isEditable = false

Swift 1, 2:

textView.editable = false

Objective-C:

textView.editable = NO;
小ぇ时光︴ 2025-01-02 01:50:37
textView.editable = NO;

文档中提到了这一点。

关于滚动;当内容大小超过 UITextView 的框架大小时,您的 UITextView 将滚动。

textView.editable = NO;

It's mentioned in the documentation.

And about the scrolling; Your UITextView will scroll when the content size exceeds the frame size of your UITextView.

贪了杯 2025-01-02 01:50:37
textview.editable = false // for swift language
textview.selectable = false //

// override textview delegates
func textViewShouldBeginEditing(textView: UITextView) -> Bool {
    return false
}
textview.editable = false // for swift language
textview.selectable = false //

// override textview delegates
func textViewShouldBeginEditing(textView: UITextView) -> Bool {
    return false
}
阳光的暖冬 2025-01-02 01:50:37

您还可以通过故事板设置行为。只需取消选中“可编辑”,如下图所示

在此处输入图像描述

you can also set the behavior through storyboard. just uncheck the 'editable' like the image below

enter image description here

℡Ms空城旧梦 2025-01-02 01:50:37

更新 Swift 3+

editableselectable 已重命名为 isEditableisSelectable

textView.isEditable = false
textView.isSelectable = false

一个布尔值,指示接收器是否可编辑。该属性的默认值为 true。

 var isEditable: Bool { 获取设置 }

一个布尔值,指示接收器是否可选。此属性控制用户选择内容以及与 URL 和文本附件交互的能力。默认值为 true。

 var isSelectable: Bool { 获取设置 }

Update Swift 3+

editable and selectable have been renamed to isEditable and isSelectable

textView.isEditable = false
textView.isSelectable = false

A Boolean value indicating whether the receiver is editable. The default value of this property is true.

 var isEditable: Bool { get set }

A Boolean value indicating whether the receiver is selectable. This property controls the ability of the user to select content and interact with URLs and text attachments. The default value is true.

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