在xib中自定义视图不工作
问题描述:
我有我的`.xib'这样的自定义视图VPMOTPView。 在xib中自定义视图不工作
class VerifyOTP: UIView {
@IBOutlet weak var otpView: VPMOTPView!
var emailID = ""
var userID = ""
@IBAction func resendOTPAction(_ sender: UIButton) {
print("asdds")
}
override func awakeFromNib() {
super.awakeFromNib()
otpView.otpFieldsCount = 4
otpView.otpFieldDefaultBorderColor = UIColor.blue
otpView.otpFieldEnteredBorderColor = UIColor.red
otpView.otpFieldBorderWidth = 2
otpView.delegate = self
// Create the UI
otpView.initalizeUI()
}
}
extension VerifyOTP: VPMOTPViewDelegate {
func hasEnteredAllOTP(hasEntered: Bool) {
print("Has entered all OTP? \(hasEntered)")
}
func enteredOTP(otpString: String) {
print("OTPString: \(otpString)")
}
}
然后在我的“视图控制器”
var verifyOTPView: VerifyOTP?
self.verifyOTPView = VerifyOTP.fromNib()
self.verifyOTPView?.frame = CGRect(x: 20, y: 0, width: screenSize.width - 40, height: screenSize.height/3)
self.view.addSubview(self.verifyOTPView!)
但是,这是我可以在屏幕上看到我的重发OTP按钮,但不显示OTPVIEW。
您是否将其课程设置为故事板中的相应课程? –