[英]Swift - Default behavior for UITextFields
我有一個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()
}
這是例外:
由於未捕獲的異常“ NSInvalidArgumentException”而導致BlockquoteTerminate應用程序,原因:“-[[CustomTextField setFocusOn:]:無法識別的選擇器發送到實例0x7ff048d0b270”
任何幫助/提示將不勝感激!
TIA,彌爾頓
您的選擇器沒有參數,因此不需要冒號,因此請嘗試:
self.addTarget(self, action: "setFocusOn", forControlEvents: UIControlEvents.EditingDidBegin)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.