Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions Pod/PinCodeTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}

Expand Down Expand Up @@ -274,9 +279,12 @@ import UIKit
let underlineY = bounds.height / 2 + totalLabelHeight / 2 + underlineVMargin

for i in 0..<underlines.count {
let underline = underlines[i]
if !showBorderInsteadOfUnderline {
let underline = underlines[i]
underline.frame = CGRect(x: currentUnderlineX, y: underlineY, width: underlineWidth, height: underlineHeight)
}

let background = backgrounds[i]
underline.frame = CGRect(x: currentUnderlineX, y: underlineY, width: underlineWidth, height: underlineHeight)
background.frame = CGRect(x: currentUnderlineX, y: 0, width: underlineWidth, height: bounds.height)
currentUnderlineX += underlineWidth + underlineHSpacing
}
Expand Down