gpt4 book ai didi

ios - 如何使 UITextView 在 Swift 中可选择

转载 作者:可可西里 更新时间:2023-11-01 02:26:21 25 4
gpt4 key购买 nike

我在 Swift 中有这个 UITextView:

let contactText = UITextView(frame: CGRectMake(0,0,200,50))
contactText.selectable = true
contactText.dataDetectorTypes = UIDataDetectorTypes.Link
contactText.userInteractionEnabled = true
contactText.editable = false
contactText.text = "Some text goes here and some website here www.google.com"
self.view.addSubview(contactText)

我希望能够双击或点击并按住以选择文本,然后为用户提供选择全部或复制的选项(就像大多数应用程序一样)。上面的代码虽然看起来应该有效,但没有起作用,还有其他方法吗?

编辑:

上面的代码确实有效,但不起作用的原因(还不是 100% 肯定)可能是因为 UITextView 位于一个附加了 PanGestureRecognizer 的 UIView 中,所以也许这会阻止它?有什么想法吗?

最佳答案

要使 UITextView 可选,您只需添加以下两行:

你的TextView.selectable = true

你的TextView.userInteractionEnabled = true

关于ios - 如何使 UITextView 在 Swift 中可选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27709965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com