如何在SkyFloatingLabelTextField在swift禁用复制粘贴功能?



我使用的是UITextfield的SkyFloatingLabelTextField类,我如何禁用这个文本字段的复制和粘贴功能。

将此技术用于自定义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)
}
}

创建一个自定义类,继承自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)
}
}

相关内容

  • 没有找到相关文章

最新更新