我是UITextField的扩展,希望在处于活动/非活动/无效时更改样式。我想在定制中完成所有这些,以避免重复代码。
当我在自定义文本字段(在视图中)之外设置它时它很有用,但是当我想这样设置时抛出异常。当字段变为活动(聚焦)时,抛出异常,而不是在它出现时抛出。
class LoginTextField: UITextField {
@IBInspectable var strokeColor: UIColor = UIColor.captionColor()
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.addTarget(self, action: "setFocusOn:", forControlEvents: UIControlEvents.EditingDidBegin)
}
func setFocusOn(){
strokeColor = UIColor.captionUnderlineColor()
}
以下是例外:
BlockquoteTerminating应用程序由于未捕获的异常' NSInvalidArgumentException',原因:' - [CustomTextField setFocusOn:]:无法识别的选择器发送到实例0x7ff048d0b270'
非常感谢任何帮助/提示!
TIA, 米尔顿
答案 0 :(得分:2)
你的选择器没有参数所以不需要冒号,所以试试:
self.addTarget(self, action: "setFocusOn", forControlEvents: UIControlEvents.EditingDidBegin)