Ios 使用IBInspectable在UITextField上禁用剪切、复制和粘贴
请查找以下不适用于我的代码Ios 使用IBInspectable在UITextField上禁用剪切、复制和粘贴,ios,swift,swift2,ibdesignable,Ios,Swift,Swift2,Ibdesignable,请查找以下不适用于我的代码 @IBInspectable var pasteOption: Bool = true { didSet { func canPerformAction(action: Selector, withSender sender: AnyObject) -> Bool { if action == "selectAll:" { return pasteO
@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)
}
}
}
我想使用
IBInspectable
禁用对我的UITextfield
的剪切、复制和粘贴。您需要这样定义var:
@IBInspectable var pasteOption: Bool = true
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)
}
然后重写UITextField
的canperformation
函数,如下所示:
@IBInspectable var pasteOption: Bool = true
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
和paste
)每当文本字段打开编辑菜单时。此代码驻留在哪个类中?Seprate UITextField