xib中的自定义视图无法正常工作

时间:2017-04-14 14:53:46

标签: ios swift uiview xib

我的`.xib'中有VPMOTPView个自定义视图。 enter image description here

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)")
    }
}

然后在我的'ViewController'

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!)

但是通过这个我可以在屏幕上看到我的RESEND OTP按钮,但不显示OTPVIEW。

1 个答案:

答案 0 :(得分:0)

从截图中看,您的观点设置有任何限制吗?

如果没有尝试添加约束,看看是否能解决问题。