Swift 3-如何覆盖子类中的方法
Swift 3- How to override a method in subclass
在 Swift 3 中,我想在其子类中重写 caretRectForPosition 方法 UITextField
说 CustomTextField
这是我的代码,在 Swift 2.3
之前工作正常
import UIKit
class CustomTextField: UITextField {
override func caretRectForPosition(position: UITextPosition) -> CGRect {
return CGRect.zero
}
}
但在 Swift 3 中它显示了一个编译时错误 Method does not override any method from its superclass.
谁能帮我解决这个问题。
我正在使用此代码来隐藏文本字段的光标。
提前致谢。
在Swift3中caretRectForPosition(position:)
改为caretRect(for:)
.
override func caretRect(for position: UITextPosition) -> CGRect {
return CGRect.zero
}
查看 Apple Documentation 了解有关 UITextInput
的更多详细信息。
在 Swift 3 中,我想在其子类中重写 caretRectForPosition 方法 UITextField
说 CustomTextField
这是我的代码,在 Swift 2.3
之前工作正常import UIKit
class CustomTextField: UITextField {
override func caretRectForPosition(position: UITextPosition) -> CGRect {
return CGRect.zero
}
}
但在 Swift 3 中它显示了一个编译时错误 Method does not override any method from its superclass.
谁能帮我解决这个问题。
我正在使用此代码来隐藏文本字段的光标。
提前致谢。
在Swift3中caretRectForPosition(position:)
改为caretRect(for:)
.
override func caretRect(for position: UITextPosition) -> CGRect {
return CGRect.zero
}
查看 Apple Documentation 了解有关 UITextInput
的更多详细信息。