Skip to content

Commit 40ee0fc

Browse files
committed
Added a default border colour prior to selection
1 parent 24000fc commit 40ee0fc

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

CBPinEntryView.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'CBPinEntryView'
11-
s.version = '1.1.0'
11+
s.version = '1.2.0'
1212
s.summary = 'A view for entering arbitrary length numerical pins or codes written in Swift 3.0.'
1313

1414
# This description is used to generate tags and improve search results.

CBPinEntryView/Classes/CBPinEntryView.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import UIKit
1515
@IBInspectable var entryCornerRadius: CGFloat = CBPinEntryViewDefaults.entryCornerRadius
1616

1717
@IBInspectable var entryBorderWidth: CGFloat = CBPinEntryViewDefaults.entryBorderWidth
18+
@IBInspectable var entryDefaultBorderColour: UIColor = CBPinEntryViewDefaults.entryDefaultBorderColour
1819
@IBInspectable var entryBorderColour: UIColor = CBPinEntryViewDefaults.entryBorderColour
1920
@IBInspectable var entryErrorBorderColour: UIColor = CBPinEntryViewDefaults.entryErrorColour
2021

@@ -86,8 +87,8 @@ import UIKit
8687
button.titleLabel!.font = entryFont
8788

8889
button.layer.cornerRadius = entryCornerRadius
89-
button.layer.borderColor = entryBorderColour.cgColor
90-
button.layer.borderWidth = 0.0
90+
button.layer.borderColor = entryDefaultBorderColour.cgColor
91+
button.layer.borderWidth = entryBorderWidth
9192

9293
button.tag = i + 1
9394

@@ -106,9 +107,9 @@ import UIKit
106107
button.layer.borderColor = entryBorderColour.cgColor
107108

108109
if button.tag == entryIndex {
109-
button.layer.borderWidth = 1
110+
button.layer.borderColor = entryBorderColour.cgColor
110111
} else {
111-
button.layer.borderWidth = 0
112+
button.layer.borderColor = entryDefaultBorderColour.cgColor
112113
}
113114
}
114115

@@ -165,25 +166,25 @@ extension CBPinEntryView: UITextFieldDelegate {
165166
if !deleting {
166167
for button in entryButtons {
167168
if button.tag == newLength {
168-
button.layer.borderWidth = 0
169+
button.layer.borderColor = entryDefaultBorderColour.cgColor
169170
UIView.setAnimationsEnabled(false)
170171
button.setTitle(string, for: .normal)
171172
UIView.setAnimationsEnabled(true)
172173
} else if button.tag == newLength + 1 {
173-
button.layer.borderWidth = entryBorderWidth
174+
button.layer.borderColor = entryBorderColour.cgColor
174175
} else {
175-
button.layer.borderWidth = 0.0
176+
button.layer.borderColor = entryDefaultBorderColour.cgColor
176177
}
177178
}
178179
} else {
179180
for button in entryButtons {
180181
if button.tag == oldLength {
181-
button.layer.borderWidth = entryBorderWidth
182+
button.layer.borderColor = entryBorderColour.cgColor
182183
UIView.setAnimationsEnabled(false)
183184
button.setTitle("", for: .normal)
184185
UIView.setAnimationsEnabled(true)
185186
} else {
186-
button.layer.borderWidth = 0
187+
button.layer.borderColor = entryDefaultBorderColour.cgColor
187188
}
188189
}
189190
}

CBPinEntryView/Classes/CBPinEntryViewDefaults.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ struct CBPinEntryViewDefaults {
1919
// Default border width
2020
static let entryBorderWidth: CGFloat = 1
2121

22+
// Default border colour of fields before selection
23+
static let entryDefaultBorderColour: UIColor = UIColor.clear
24+
2225
// Default border colour of currently editing field
2326
static let entryBorderColour: UIColor = UIColor(red: 69/255, green: 78/255, blue: 86/255, alpha: 1.0)
2427

Example/CBPinEntryView/Base.lproj/Main.storyboard

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
33
<device id="retina4_0" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
7-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
7+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
88
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1010
</dependencies>
@@ -35,6 +35,9 @@
3535
<userDefinedRuntimeAttribute type="number" keyPath="entryCornerRadius">
3636
<real key="value" value="3"/>
3737
</userDefinedRuntimeAttribute>
38+
<userDefinedRuntimeAttribute type="color" keyPath="entryDefaultBorderColour">
39+
<color key="value" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
40+
</userDefinedRuntimeAttribute>
3841
</userDefinedRuntimeAttributes>
3942
</view>
4043
<stackView opaque="NO" contentMode="scaleToFill" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="l00-Oi-KOV">

0 commit comments

Comments
 (0)