如果像UITextField(UITextView,UIWebView)一样长时间按下UILabel,我可以实现“选择”和“复制”吗? [英] Can I implement “select” and “copy” on UILabel when it has a long press just as UITextField (UITextView、UIWebView), and how?

查看:81
本文介绍了如果像UITextField(UITextView,UIWebView)一样长时间按下UILabel,我可以实现“选择”和“复制”吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请给我一个手〜我想知道如何使UILabel有一个系统剪贴板(例如复制和选择),如UITextField(UITextView,UIWebView),当它有一个长按,这使我可以复制我想要的文本。我已经在Github上阅读了一些演示,但是,它们总是只包含复制功能,这使我无法选择我要复制的文本。目前我想在UILabel上实现选择,但我不知道如何解决。

我可以使用UITextField而无需编辑功能吗?但是一旦我关闭编辑功能,长按时就没有系统剪贴板。或者,如果有一个更简单的方法可以解决?谢谢!

解决方案

在XCode的界面构建器中,您可以在属性检查器中为UILabel设置选项可选。


< blockquote> mybe你应该使用coretext来计算按下位置以获得用户选择的响铃。


Please give me a hand~ I wanna know how to make UILabel have a system Clipboard(e.g. copy and select) like UITextField (UITextView、UIWebView) when it has a long press, which makes me can copy the text I want. I have read some demo on Github, however, they always only contain copy function, which makes me can't choose the text I want to copy. At present I wanna implement "select" on UILabel but I don't know how to work out.
Can I use UITextField without editing function? But once I turn off editing function, there is no system Clipboard when it has a long press. Or if there is a simpler method to work out? Thanks!

解决方案

In the interface builder of XCode you can set the option "Selectable" in the Attribute inspector for an UILabel.


mybe you should use coretext to calculate the press position to get the rang the user select.


这篇关于如果像UITextField(UITextView,UIWebView)一样长时间按下UILabel,我可以实现“选择”和“复制”吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆