我正在为 UITextfield 使用 SkyFloatingLabelTextField 类,如何禁用此文本文件上的复制和粘贴功能。
2 回答
1
将此技术用于自定义文本字段
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)
}
}
于 2021-10-07T06:52:13.987 回答
1
创建一个继承自 SkyFloatingLabelTextField 类的自定义类,然后赋值。
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)
}
}
如果您想为整个项目和所有文本字段添加此扩展名。
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)
}
}
于 2021-10-07T06:56:54.333 回答