From 971ba5eff2fbd01cc58c8df5a2954966c2f84652 Mon Sep 17 00:00:00 2001 From: Rafael Duarte Lucchesi Date: Fri, 4 Dec 2020 16:01:32 -0300 Subject: [PATCH 1/2] Improve way to set correct underline color --- Pod/PinCodeTextField.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Pod/PinCodeTextField.swift b/Pod/PinCodeTextField.swift index 06b2438..3bd5dbd 100644 --- a/Pod/PinCodeTextField.swift +++ b/Pod/PinCodeTextField.swift @@ -207,15 +207,15 @@ 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) } } From f880200f2d6c0567e7d56be6e1faa8fc408d23b5 Mon Sep 17 00:00:00 2001 From: Rafael Duarte Lucchesi Date: Fri, 4 Dec 2020 16:18:38 -0300 Subject: [PATCH 2/2] Add flag to print border instead of underline --- Pod/PinCodeTextField.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Pod/PinCodeTextField.swift b/Pod/PinCodeTextField.swift index 3bd5dbd..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 @@ -220,9 +221,13 @@ import UIKit } 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..