Skip to content

Commit 9ca5244

Browse files
author
Athul Sai
committed
Fixed issue #3 and added option to set keyboard appearance
1 parent ffca160 commit 9ca5244

6 files changed

Lines changed: 115 additions & 27 deletions

File tree

Example/KWVerificationCodeView/Base.lproj/Main.storyboard

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<subviews>
2424
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ekS-Ew-GpT" userLabel="verificationCodeView" customClass="KWVerificationCodeView" customModule="KWVerificationCodeView">
2525
<rect key="frame" x="33" y="273" width="310" height="62"/>
26-
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
26+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
2727
<constraints>
2828
<constraint firstAttribute="width" constant="310" id="SmR-e4-qbu"/>
2929
<constraint firstAttribute="height" constant="62" id="mda-A6-NvC"/>
@@ -32,12 +32,6 @@
3232
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
3333
<integer key="value" value="5"/>
3434
</userDefinedRuntimeAttribute>
35-
<userDefinedRuntimeAttribute type="color" keyPath="underlineSelectedColor">
36-
<color key="value" red="0.068236636075229451" green="0.44572890228426398" blue="0.12406174271236946" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
37-
</userDefinedRuntimeAttribute>
38-
<userDefinedRuntimeAttribute type="color" keyPath="underlineColor">
39-
<color key="value" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
40-
</userDefinedRuntimeAttribute>
4135
</userDefinedRuntimeAttributes>
4236
</view>
4337
<button opaque="NO" contentMode="scaleToFill" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Skh-28-8br" userLabel="submitButton">
@@ -52,7 +46,7 @@
5246
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
5347
</state>
5448
<state key="disabled">
55-
<color key="titleColor" red="1" green="0.79129829853778799" blue="0.59988017074977373" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
49+
<color key="titleColor" red="1" green="0.7912982985" blue="0.59988017069999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
5650
</state>
5751
<userDefinedRuntimeAttributes>
5852
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
@@ -72,11 +66,11 @@
7266
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Enter Code" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="P6k-pN-VEP" userLabel="promptLabel">
7367
<rect key="frame" x="149" y="233" width="77" height="18"/>
7468
<fontDescription key="fontDescription" type="system" pointSize="15"/>
75-
<nil key="textColor"/>
69+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
7670
<nil key="highlightedColor"/>
7771
</label>
7872
</subviews>
79-
<color key="backgroundColor" red="0.93725490570000003" green="0.93725490570000003" blue="0.95686274770000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
73+
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
8074
<constraints>
8175
<constraint firstItem="ekS-Ew-GpT" firstAttribute="top" secondItem="P6k-pN-VEP" secondAttribute="bottom" constant="22" id="H7u-LC-n82"/>
8276
<constraint firstItem="ekS-Ew-GpT" firstAttribute="top" secondItem="6e0-Am-MUv" secondAttribute="bottom" constant="90" id="HQQ-Ne-ux5"/>

KWVerificationCodeView/Classes/KWTextFieldView.swift

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,49 @@ protocol KWTextFieldDelegate: class {
2525
underlineView.backgroundColor = underlineColor
2626
}
2727
}
28-
@IBInspectable var underlineSelectedColor: UIColor = UIColor.blue
28+
@IBInspectable var underlineSelectedColor: UIColor = UIColor.black
29+
@IBInspectable var textColor: UIColor = UIColor.darkText {
30+
didSet {
31+
numberTextField.textColor = textColor
32+
}
33+
}
34+
@IBInspectable var textSize: CGFloat = 24.0 {
35+
didSet {
36+
numberTextField.font = UIFont.systemFont(ofSize: textSize)
37+
}
38+
}
39+
@IBInspectable var textFont: String = "" {
40+
didSet {
41+
if textFont.trim() == "" {
42+
numberTextField.font = UIFont.systemFont(ofSize: textSize)
43+
} else {
44+
if let font = UIFont(name: textFont, size: textSize) {
45+
numberTextField.font = font
46+
} else {
47+
numberTextField.font = UIFont.systemFont(ofSize: textSize)
48+
}
49+
}
50+
}
51+
}
52+
@IBInspectable var textFieldBackgroundColor: UIColor = UIColor.clear {
53+
didSet {
54+
numberTextField.backgroundColor = textFieldBackgroundColor
55+
}
56+
}
57+
@IBInspectable var textFieldTintColor: UIColor = UIColor.blue {
58+
didSet {
59+
numberTextField.tintColor = textFieldTintColor
60+
}
61+
}
62+
@IBInspectable var darkKeyboard: Bool = false {
63+
didSet {
64+
if darkKeyboard {
65+
numberTextField.keyboardAppearance = .dark
66+
} else {
67+
numberTextField.keyboardAppearance = .light
68+
}
69+
}
70+
}
2971

3072
// MARK: - IBOutlets
3173
@IBOutlet weak var numberTextField: UITextField!

KWVerificationCodeView/Classes/KWTextFieldView.xib

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
2121
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2222
<subviews>
23-
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="uky-3e-m7A" userLabel="numberTextField">
23+
<textField clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="uky-3e-m7A" userLabel="numberTextField">
2424
<rect key="frame" x="0.0" y="0.0" width="50" height="48"/>
2525
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
26-
<color key="tintColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
26+
<color key="tintColor" red="0.0" green="0.0" blue="1" alpha="1" colorSpace="calibratedRGB"/>
2727
<nil key="textColor"/>
2828
<fontDescription key="fontDescription" type="system" pointSize="24"/>
2929
<textInputTraits key="textInputTraits" keyboardType="numberPad"/>
3030
</textField>
3131
<view userInteractionEnabled="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="eC6-EU-k8d" userLabel="underlineView">
3232
<rect key="frame" x="0.0" y="39" width="50" height="1"/>
33-
<color key="backgroundColor" red="0.66666666666666663" green="0.66666666666666663" blue="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
33+
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
3434
<constraints>
3535
<constraint firstAttribute="height" constant="1" id="pFW-zo-tEa"/>
3636
</constraints>

KWVerificationCodeView/Classes/KWVerificationCodeView.swift

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,81 @@ public protocol KWVerificationCodeViewDelegate: class {
2525
}
2626
}
2727
}
28-
@IBInspectable var underlineSelectedColor: UIColor = UIColor.blue {
28+
@IBInspectable var underlineSelectedColor: UIColor = UIColor.black {
2929
didSet {
3030
for textFieldView in textFieldViews {
3131
textFieldView.underlineSelectedColor = underlineSelectedColor
3232
}
3333
}
3434
}
35-
36-
// MARK: - IBOutlets
35+
@IBInspectable var textColor: UIColor = UIColor.darkText {
36+
didSet {
37+
for textFieldView in textFieldViews {
38+
textFieldView.numberTextField.textColor = textColor
39+
}
40+
}
41+
}
42+
@IBInspectable var textSize: CGFloat = 24.0 {
43+
didSet {
44+
for textFieldView in textFieldViews {
45+
textFieldView.numberTextField.font = UIFont.systemFont(ofSize: textSize)
46+
}
47+
}
48+
}
49+
@IBInspectable var textFont: String = "" {
50+
didSet {
51+
if textFont.trim() == "" {
52+
textFieldFont = UIFont.systemFont(ofSize: textSize)
53+
} else {
54+
if let font = UIFont(name: textFont.trim(), size: textSize) {
55+
textFieldFont = font
56+
} else {
57+
textFieldFont = UIFont.systemFont(ofSize: textSize)
58+
}
59+
}
60+
for textFieldView in textFieldViews {
61+
textFieldView.numberTextField.font = textFieldFont
62+
}
63+
}
64+
}
65+
@IBInspectable var textFieldBackgroundColor: UIColor = UIColor.clear {
66+
didSet {
67+
for textFieldView in textFieldViews {
68+
textFieldView.numberTextField.backgroundColor = textFieldBackgroundColor
69+
}
70+
}
71+
}
72+
@IBInspectable var textFieldTintColor: UIColor = UIColor.blue {
73+
didSet {
74+
for textFieldView in textFieldViews {
75+
textFieldView.numberTextField.tintColor = textFieldTintColor
76+
}
77+
}
78+
}
79+
@IBInspectable var darkKeyboard: Bool = false {
80+
didSet {
81+
if darkKeyboard {
82+
keyboardColor = .dark
83+
} else {
84+
keyboardColor = .light
85+
}
86+
87+
for textFieldView in textFieldViews {
88+
textFieldView.numberTextField.keyboardAppearance = keyboardColor
89+
}
90+
}
91+
}
92+
93+
// MARK: - IBOutlets
3794
@IBOutlet weak private var textFieldView1: KWTextFieldView!
3895
@IBOutlet weak private var textFieldView2: KWTextFieldView!
3996
@IBOutlet weak private var textFieldView3: KWTextFieldView!
4097
@IBOutlet weak private var textFieldView4: KWTextFieldView!
4198

4299
// MARK: - Variables
100+
private var keyboardColor = UIKeyboardAppearance.default
101+
private var textFieldFont = UIFont.systemFont(ofSize: 24.0)
102+
43103
lazy var textFieldViews: [KWTextFieldView] = {
44104
[unowned self] in
45105

KWVerificationCodeView/Classes/KWVerificationCodeView.xib

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</connections>
1919
</placeholder>
2020
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
21-
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="DUS-Hj-ChZ">
21+
<view userInteractionEnabled="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="DUS-Hj-ChZ">
2222
<rect key="frame" x="0.0" y="0.0" width="375" height="62"/>
2323
<subviews>
2424
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="3tC-Ut-0VN" userLabel="textFieldView1" customClass="KWTextFieldView" customModule="KWVerificationCodeView">
@@ -40,27 +40,19 @@
4040
<rect key="frame" x="284" y="6" width="81" height="50"/>
4141
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
4242
</view>
43-
<view alpha="0.050000000000000003" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Uba-Pv-jsf" userLabel="topView">
44-
<rect key="frame" x="0.0" y="0.0" width="375" height="62"/>
45-
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
46-
</view>
4743
</subviews>
4844
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
4945
<constraints>
5046
<constraint firstItem="3tC-Ut-0VN" firstAttribute="leading" secondItem="DUS-Hj-ChZ" secondAttribute="leading" constant="10" id="0di-mx-zfw"/>
5147
<constraint firstAttribute="bottom" secondItem="3tC-Ut-0VN" secondAttribute="bottom" constant="6" id="5uF-mn-LoT"/>
52-
<constraint firstItem="Uba-Pv-jsf" firstAttribute="leading" secondItem="DUS-Hj-ChZ" secondAttribute="leading" id="8uT-N2-xM4"/>
5348
<constraint firstItem="jRf-YT-Rjh" firstAttribute="height" secondItem="3tC-Ut-0VN" secondAttribute="height" id="Gb4-Os-cwr"/>
5449
<constraint firstItem="vt9-dd-ekk" firstAttribute="top" secondItem="DUS-Hj-ChZ" secondAttribute="top" constant="6" id="Kg2-dv-3YJ"/>
5550
<constraint firstItem="jRf-YT-Rjh" firstAttribute="width" secondItem="3tC-Ut-0VN" secondAttribute="width" id="U4v-Ht-Drn"/>
5651
<constraint firstItem="vt9-dd-ekk" firstAttribute="width" secondItem="uqQ-2Z-1XV" secondAttribute="width" id="VK2-dB-JL0"/>
57-
<constraint firstAttribute="bottom" secondItem="Uba-Pv-jsf" secondAttribute="bottom" id="VpP-Ye-4LD"/>
5852
<constraint firstItem="jRf-YT-Rjh" firstAttribute="top" secondItem="DUS-Hj-ChZ" secondAttribute="top" constant="6" id="Vvq-kp-ykE"/>
5953
<constraint firstAttribute="trailing" secondItem="vt9-dd-ekk" secondAttribute="trailing" constant="10" id="fPo-e5-fRn"/>
60-
<constraint firstItem="Uba-Pv-jsf" firstAttribute="top" secondItem="DUS-Hj-ChZ" secondAttribute="top" id="gfu-mb-7SY"/>
6154
<constraint firstItem="vt9-dd-ekk" firstAttribute="height" secondItem="uqQ-2Z-1XV" secondAttribute="height" id="jCR-aZ-KYb"/>
6255
<constraint firstItem="uqQ-2Z-1XV" firstAttribute="height" secondItem="jRf-YT-Rjh" secondAttribute="height" id="nlt-Sw-o2S"/>
63-
<constraint firstAttribute="trailing" secondItem="Uba-Pv-jsf" secondAttribute="trailing" id="q5B-Lv-1ay"/>
6456
<constraint firstItem="uqQ-2Z-1XV" firstAttribute="leading" secondItem="jRf-YT-Rjh" secondAttribute="trailing" constant="10" id="rEH-pO-Tk3"/>
6557
<constraint firstItem="uqQ-2Z-1XV" firstAttribute="width" secondItem="jRf-YT-Rjh" secondAttribute="width" id="rtg-SH-V0Y"/>
6658
<constraint firstItem="vt9-dd-ekk" firstAttribute="leading" secondItem="uqQ-2Z-1XV" secondAttribute="trailing" constant="10" id="u6T-vB-S9e"/>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ It is possile to set the default and selected colors of the underline in the *St
4141

4242
### Delegate
4343

44-
`KWVerificationCodeViewDelegate` has a method `didChangeVerificationCode()`, which you can implement to check for valid code in real time. This comes handy in stituations where you have to enable the submit button only if the verification code is valid.
44+
`KWVerificationCodeViewDelegate` has a method `didChangeVerificationCode()`, which you can implement to check for valid code in real time. This comes handy in situations where you have to enable the submit button only if the verification code is valid.
4545

4646
## Author
4747

0 commit comments

Comments
 (0)