Skip to content

Commit

Permalink
VerificationCode View becomes firstResponder on load
Browse files Browse the repository at this point in the history
  • Loading branch information
kpavankotesh committed Mar 5, 2018
1 parent cdf255e commit 6800688
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions KWVerificationCodeView/Classes/KWVerificationCodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public protocol KWVerificationCodeViewDelegate: class {

@IBInspectable public var digits: UInt8 = 4 {
didSet {
updateNumberOfDigits()
setupTextFieldViews()
}
}

Expand Down Expand Up @@ -139,32 +139,6 @@ public protocol KWVerificationCodeViewDelegate: class {
setup()
}

// MARK: - Private Methods
private func updateNumberOfDigits() {
textFieldViews.forEach { $0.removeFromSuperview() }
textFieldViews.removeAll()

let textFieldViewWidth = (frame.size.width - (textFieldViewLeadingSpace * (CGFloat(requiredDigits) + 1))) / CGFloat(requiredDigits)
let textFieldViewHeight: CGFloat = frame.size.height - (textFieldViewVerticalSpace * 2)
var currentX = textFieldViewLeadingSpace
for _ in 0..<requiredDigits {
let textFieldView = KWTextFieldView(frame: CGRect(x: currentX, y: textFieldViewVerticalSpace, width: textFieldViewWidth, height: textFieldViewHeight))
textFieldView.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin, .flexibleWidth]
addSubview(textFieldView)
textFieldView.delegate = self
textFieldViews.append(textFieldView)
currentX += (textFieldViewWidth + textFieldViewLeadingSpace)
}

textFieldViews[0].numberTextField.text = " "
}

private func setup() {
loadViewFromNib()
setupVerificationCodeViews()
updateNumberOfDigits()
}

// MARK: - Public Methods
public func getVerificationCode() -> String {
var verificationCode = ""
Expand All @@ -186,7 +160,33 @@ public protocol KWVerificationCodeViewDelegate: class {
}

// MARK: - Private Methods
private func setupVerificationCodeViews() {
private func setup() {
loadViewFromNib()

setupTextFieldViews()
setupVerificationCodeView()
}

private func setupTextFieldViews() {
textFieldViews.forEach { $0.removeFromSuperview() }
textFieldViews.removeAll()

let textFieldViewWidth = (frame.size.width - (textFieldViewLeadingSpace * (CGFloat(requiredDigits) + 1))) / CGFloat(requiredDigits)
let textFieldViewHeight: CGFloat = frame.size.height - (textFieldViewVerticalSpace * 2)
var currentX = textFieldViewLeadingSpace
for _ in 0..<requiredDigits {
let textFieldView = KWTextFieldView(frame: CGRect(x: currentX, y: textFieldViewVerticalSpace, width: textFieldViewWidth, height: textFieldViewHeight))
textFieldView.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin, .flexibleWidth]
addSubview(textFieldView)
textFieldView.delegate = self
textFieldViews.append(textFieldView)
currentX += (textFieldViewWidth + textFieldViewLeadingSpace)
}

textFieldViews[0].numberTextField.text = " "
}

private func setupVerificationCodeView() {
for textFieldView in textFieldViews {
textFieldView.delegate = self
}
Expand Down

0 comments on commit 6800688

Please sign in to comment.