[英]How to disable the copy paste functionality in SkyFloatingLabelTextField in swift?
I am using the SkyFloatingLabelTextField class for UITextfield,How can I disable the Copy and paste functionality on this textfiled.我正在为 UITextfield 使用 SkyFloatingLabelTextField class,如何禁用此文本文件上的复制和粘贴功能。
Use this technique for custom textField将此技术用于自定义 textField
class SkyFloatingLabelTextField: UITextField {
open override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == #selector(UIResponderStandardEditActions.paste(_:)) {
return false
}
return super.canPerformAction(action, withSender: sender)
}
}
Create a custom class inherited from SkyFloatingLabelTextField class and then assign.创建一个自定义的 class 继承自 SkyFloatingLabelTextField class 然后赋值。
class FloatingTextField: SkyFloatingLabelTextField {
open override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == #selector(UIResponderStandardEditActions.paste(_:)) ||
action == #selector(UIResponderStandardEditActions.copy(_:)) {
return false
}
return super.canPerformAction(action, withSender: sender)
}
}
If you want for the whole project and all textfield add this extension.如果您想要为整个项目和所有文本字段添加此扩展。
extension SkyFloatingLabelTextField {
open override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == #selector(UIResponderStandardEditActions.paste(_:)) ||
action == #selector(UIResponderStandardEditActions.copy(_:)) {
return false
}
return super.canPerformAction(action, withSender: sender)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.