diff --git a/Pod/PinCodeTextField.swift b/Pod/PinCodeTextField.swift index 06b2438..e57f6ed 100644 --- a/Pod/PinCodeTextField.swift +++ b/Pod/PinCodeTextField.swift @@ -45,7 +45,8 @@ import UIKit @IBInspectable public var characterBackgroundColor: UIColor = UIColor.clear @IBInspectable public var characterBackgroundCornerRadius: CGFloat = 0 @IBInspectable public var highlightInputUnderline: Bool = false - + @IBInspectable public var showBorderInsteadOfUnderline: Bool = false + //MARK: Customizable from code public var keyboardType: UIKeyboardType = UIKeyboardType.alphabet public var keyboardAppearance: UIKeyboardAppearance = UIKeyboardAppearance.default @@ -207,22 +208,26 @@ import UIKit } } + private func underlineColorForIndex(_ index: Int) -> UIColor { + (!highlightInputUnderline || !isInput(index)) && isPlaceholder(index) + ? underlineColor + : updatedUnderlineColor + } + private func updateUnderlines() { - for label in labels { - let index = labels.firstIndex(of: label) ?? 0 - if (!highlightInputUnderline || !isInput(index)) && isPlaceholder(index) { - underlines[index].backgroundColor = underlineColor - } - else{ - underlines[index].backgroundColor = updatedUnderlineColor - } + for (index, underline) in underlines.enumerated() { + underline.backgroundColor = underlineColorForIndex(index) } } private func updateBackgrounds() { - for background in backgrounds { + for (index, background) in backgrounds.enumerated() { background.backgroundColor = characterBackgroundColor background.layer.cornerRadius = characterBackgroundCornerRadius + if showBorderInsteadOfUnderline { + background.layer.borderWidth = underlineHeight + background.layer.borderColor = underlineColorForIndex(index).cgColor + } } } @@ -274,9 +279,12 @@ import UIKit let underlineY = bounds.height / 2 + totalLabelHeight / 2 + underlineVMargin for i in 0..