请找到以下不适合我的代码。
@IBInspectable var pasteOption: Bool = true {
didSet {
func canPerformAction(action: Selector, withSender sender: AnyObject) -> Bool {
if action == "selectAll:" {
return pasteOption
}
if action == "select:" {
return pasteOption
}
if action == "cut:" {
return pasteOption
}
if action == "copy:" {
return pasteOption
}
if action == "paste:" {
return pasteOption
}
return super.canPerformAction(action, withSender: sender)
}
}
}
我想使用UITextfield
禁用剪切,复制和粘贴IBInspectable
。
答案 0 :(得分:1)
您需要像这样定义您的var:
@IBInspectable var pasteOption: Bool = true
然后覆盖UITextField
的{{1}}函数,如下所示:
canPerformAction
通过这样做,您可以为函数中定义的特定操作返回override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
if action == "selectAll:" {
return pasteOption
}
if action == "select:" {
return pasteOption
}
if action == "cut:" {
return pasteOption
}
if action == "copy:" {
return pasteOption
}
if action == "paste:" {
return pasteOption
}
return super.canPerformAction(action, withSender: sender)
}
的值(pasteOption
,selectAll
,select
,cut
并且在这种情况下为copy
)任何时候您的文本字段都会打开编辑菜单。