Skip to content

Commit 950ecde

Browse files
committed
1.5.12 Background image support, #9 Reload on rest count, #8 InputAccessoryView Support and #5 issue solved
1 parent 33ad4f5 commit 950ecde

File tree

8 files changed

+98
-19
lines changed

8 files changed

+98
-19
lines changed

DPOTPView.framework.zip

-2.32 MB
Binary file not shown.

DPOTPView.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "DPOTPView"
19-
s.version = "1.5.11"
19+
s.version = "1.5.12"
2020
s.summary = "Customisable OTP view and Passcode view."
2121

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

DPOTPView.xcframework.zip

3.06 MB
Binary file not shown.

DPOTPView/DPOTPView.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@
305305
"@executable_path/Frameworks",
306306
"@loader_path/Frameworks",
307307
);
308-
MARKETING_VERSION = 1.5.11;
308+
MARKETING_VERSION = 1.5.12;
309309
PRODUCT_BUNDLE_IDENTIFIER = com.datt.DPOTPView;
310310
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
311311
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -337,7 +337,7 @@
337337
"@executable_path/Frameworks",
338338
"@loader_path/Frameworks",
339339
);
340-
MARKETING_VERSION = 1.5.11;
340+
MARKETING_VERSION = 1.5.12;
341341
PRODUCT_BUNDLE_IDENTIFIER = com.datt.DPOTPView;
342342
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
343343
PROVISIONING_PROFILE_SPECIFIER = "";

DPOTPView/DPOTPView/Base.lproj/Main.storyboard

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
33
<device id="retina6_1" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17505"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
8+
<capability name="System colors in document resources" minToolsVersion="11.0"/>
89
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
910
</dependencies>
1011
<scenes>
@@ -43,7 +44,7 @@
4344
<integer key="value" value="4"/>
4445
</userDefinedRuntimeAttribute>
4546
<userDefinedRuntimeAttribute type="color" keyPath="backGroundColorTextField">
46-
<color key="value" systemColor="systemGreenColor" red="0.20392156859999999" green="0.78039215689999997" blue="0.34901960780000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
47+
<color key="value" systemColor="systemGreenColor"/>
4748
</userDefinedRuntimeAttribute>
4849
<userDefinedRuntimeAttribute type="boolean" keyPath="isSecureTextEntry" value="YES"/>
4950
<userDefinedRuntimeAttribute type="boolean" keyPath="isCircleTextField" value="YES"/>
@@ -57,6 +58,7 @@
5758
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="XZU-8o-pmY" customClass="DPOTPView" customModule="DPOTPView_Example" customModuleProvider="target">
5859
<rect key="frame" x="82" y="54" width="250" height="60"/>
5960
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
61+
<color key="tintColor" systemColor="systemBlueColor"/>
6062
<constraints>
6163
<constraint firstAttribute="width" constant="250" id="cZB-G0-hzf"/>
6264
<constraint firstAttribute="height" constant="60" id="wRP-4J-J9f"/>
@@ -115,17 +117,17 @@
115117
</userDefinedRuntimeAttribute>
116118
<userDefinedRuntimeAttribute type="boolean" keyPath="dismissOnLastEntry" value="YES"/>
117119
<userDefinedRuntimeAttribute type="color" keyPath="selectedBorderColorTextField">
118-
<color key="value" systemColor="systemPinkColor" red="1" green="0.1764705882" blue="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
120+
<color key="value" systemColor="systemPinkColor"/>
119121
</userDefinedRuntimeAttribute>
120122
<userDefinedRuntimeAttribute type="color" keyPath="backGroundColorTextField">
121-
<color key="value" systemColor="systemTealColor" red="0.35294117650000001" green="0.7843137255" blue="0.98039215690000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
123+
<color key="value" systemColor="systemTealColor"/>
122124
</userDefinedRuntimeAttribute>
123125
<userDefinedRuntimeAttribute type="boolean" keyPath="isDarkKeyboard" value="YES"/>
124126
<userDefinedRuntimeAttribute type="number" keyPath="selectedBorderWidthTextField">
125127
<real key="value" value="3"/>
126128
</userDefinedRuntimeAttribute>
127129
<userDefinedRuntimeAttribute type="color" keyPath="placeholderTextColor">
128-
<color key="value" systemColor="systemRedColor" red="1" green="0.23137254900000001" blue="0.18823529410000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
130+
<color key="value" systemColor="systemRedColor"/>
129131
</userDefinedRuntimeAttribute>
130132
<userDefinedRuntimeAttribute type="string" keyPath="placeholder" value="✲✻✵✫✱✶"/>
131133
<userDefinedRuntimeAttribute type="number" keyPath="shadowRadiusTextField">
@@ -135,7 +137,7 @@
135137
<real key="value" value="0.5"/>
136138
</userDefinedRuntimeAttribute>
137139
<userDefinedRuntimeAttribute type="color" keyPath="shadowColorTextField">
138-
<color key="value" systemColor="systemPinkColor" red="1" green="0.1764705882" blue="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
140+
<color key="value" systemColor="systemPinkColor"/>
139141
</userDefinedRuntimeAttribute>
140142
<userDefinedRuntimeAttribute type="size" keyPath="shadowOffsetSizeTextField">
141143
<size key="value" width="0.0" height="0.0"/>
@@ -145,6 +147,7 @@
145147
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="DtP-Ci-7qP" customClass="DPOTPView" customModule="DPOTPView_Example" customModuleProvider="target">
146148
<rect key="frame" x="69.5" y="234" width="275" height="50"/>
147149
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
150+
<color key="tintColor" systemColor="systemOrangeColor"/>
148151
<constraints>
149152
<constraint firstAttribute="height" constant="50" id="fUH-Ah-GwS"/>
150153
<constraint firstAttribute="width" constant="275" id="la5-1V-b37"/>
@@ -161,12 +164,13 @@
161164
<real key="value" value="3"/>
162165
</userDefinedRuntimeAttribute>
163166
<userDefinedRuntimeAttribute type="color" keyPath="selectedBorderColorTextField">
164-
<color key="value" systemColor="systemRedColor" red="1" green="0.23137254900000001" blue="0.18823529410000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
167+
<color key="value" systemColor="systemRedColor"/>
165168
</userDefinedRuntimeAttribute>
166169
<userDefinedRuntimeAttribute type="boolean" keyPath="dismissOnLastEntry" value="YES"/>
167170
<userDefinedRuntimeAttribute type="number" keyPath="selectedBorderWidthTextField">
168171
<real key="value" value="4"/>
169172
</userDefinedRuntimeAttribute>
173+
<userDefinedRuntimeAttribute type="image" keyPath="backGroundImageTextField" value="globe" catalog="system"/>
170174
</userDefinedRuntimeAttributes>
171175
</view>
172176
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="tOx-qg-TIm" customClass="DPOTPView" customModule="DPOTPView_Example" customModuleProvider="target">
@@ -187,7 +191,7 @@
187191
<real key="value" value="2"/>
188192
</userDefinedRuntimeAttribute>
189193
<userDefinedRuntimeAttribute type="color" keyPath="selectedBorderColorTextField">
190-
<color key="value" systemColor="systemGreenColor" red="0.20392156859999999" green="0.78039215689999997" blue="0.34901960780000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
194+
<color key="value" systemColor="systemGreenColor"/>
191195
</userDefinedRuntimeAttribute>
192196
<userDefinedRuntimeAttribute type="boolean" keyPath="isSecureTextEntry" value="YES"/>
193197
<userDefinedRuntimeAttribute type="boolean" keyPath="dismissOnLastEntry" value="YES"/>
@@ -201,6 +205,7 @@
201205
</userDefinedRuntimeAttributes>
202206
</view>
203207
</subviews>
208+
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
204209
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
205210
<constraints>
206211
<constraint firstItem="XWD-DZ-vzi" firstAttribute="top" secondItem="XZU-8o-pmY" secondAttribute="bottom" constant="30" id="Cti-JR-mBU"/>
@@ -214,7 +219,6 @@
214219
<constraint firstItem="XWD-DZ-vzi" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="pZ6-Tt-3LK"/>
215220
<constraint firstItem="tOx-qg-TIm" firstAttribute="top" secondItem="DtP-Ci-7qP" secondAttribute="bottom" constant="30" id="qPi-Iv-UFP"/>
216221
</constraints>
217-
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
218222
</view>
219223
<connections>
220224
<outlet property="txtDPOTPView" destination="Mzr-7d-8hs" id="r5V-17-dtd"/>
@@ -225,4 +229,25 @@
225229
<point key="canvasLocation" x="131.8840579710145" y="118.52678571428571"/>
226230
</scene>
227231
</scenes>
232+
<resources>
233+
<image name="globe" catalog="system" width="128" height="121"/>
234+
<systemColor name="systemBlueColor">
235+
<color red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
236+
</systemColor>
237+
<systemColor name="systemGreenColor">
238+
<color red="0.20392156862745098" green="0.7803921568627451" blue="0.34901960784313724" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
239+
</systemColor>
240+
<systemColor name="systemOrangeColor">
241+
<color red="1" green="0.58431372549019611" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
242+
</systemColor>
243+
<systemColor name="systemPinkColor">
244+
<color red="1" green="0.17647058823529413" blue="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
245+
</systemColor>
246+
<systemColor name="systemRedColor">
247+
<color red="1" green="0.23137254901960785" blue="0.18823529411764706" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
248+
</systemColor>
249+
<systemColor name="systemTealColor">
250+
<color red="0.35294117647058826" green="0.78431372549019607" blue="0.98039215686274506" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
251+
</systemColor>
252+
</resources>
228253
</document>

DPOTPView/DPOTPView/DPOTPView/DPOTPView.swift

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,18 @@ public protocol DPOTPViewDelegate {
1919
@IBDesignable open class DPOTPView: UIView {
2020

2121
/** The number of textField that will be put in the DPOTPView */
22-
@IBInspectable open dynamic var count: Int = 4
22+
@IBInspectable open dynamic var count: Int = 4 {
23+
didSet {
24+
if isLoaded {
25+
isLoaded = false
26+
let isFirstResponder = arrTextFields.filter({$0.isFirstResponder}).first != nil
27+
initialization()
28+
if isFirstResponder {
29+
becomeFirstResponder()
30+
}
31+
}
32+
}
33+
}
2334

2435
/** Spaceing between textField in the DPOTPView */
2536
@IBInspectable open dynamic var spacing: CGFloat = 8
@@ -42,6 +53,9 @@ public protocol DPOTPViewDelegate {
4253
/** Allow only Bottom Line for the TextField */
4354
@IBInspectable open dynamic var isBottomLineTextField: Bool = false
4455

56+
/** Background Image for all textFields */
57+
@IBInspectable open dynamic var backGroundImageTextField: UIImage?
58+
4559
/** Background color for the textField */
4660
@IBInspectable open dynamic var backGroundColorTextField: UIColor = UIColor.clear
4761

@@ -93,6 +107,9 @@ public protocol DPOTPViewDelegate {
93107
open dynamic var textEdgeInsets : UIEdgeInsets?
94108
open dynamic var editingTextEdgeInsets : UIEdgeInsets?
95109

110+
open dynamic var inputViewForAll: UIView?
111+
open dynamic var inputAccessoryViewForAll: UIView?
112+
96113
open dynamic var dpOTPViewDelegate : DPOTPViewDelegate?
97114
open dynamic var keyboardType:UIKeyboardType = UIKeyboardType.asciiCapableNumberPad
98115

@@ -114,6 +131,7 @@ public protocol DPOTPViewDelegate {
114131
}
115132

116133
fileprivate var arrTextFields : [OTPBackTextField] = []
134+
fileprivate var isLoaded = false
117135
/** Override coder init, for IB/XIB compatibility */
118136
#if !TARGET_INTERFACE_BUILDER
119137
public required init?(coder aDecoder: NSCoder) {
@@ -137,7 +155,9 @@ public protocol DPOTPViewDelegate {
137155
}
138156

139157
func initialization() {
140-
if arrTextFields.count != 0 { return }
158+
if isLoaded { return }
159+
arrTextFields.forEach{ $0.removeFromSuperview() }
160+
arrTextFields = []
141161

142162
let sizeTextField = (self.bounds.width/CGFloat(count)) - (spacing)
143163

@@ -150,10 +170,17 @@ public protocol DPOTPViewDelegate {
150170
textField.tag = i * 1000
151171
textField.tintColor = tintColorTextField
152172
textField.backgroundColor = backGroundColorTextField
173+
textField.background = backGroundImageTextField
153174
textField.isSecureTextEntry = isSecureTextEntry
154175
textField.font = fontTextField
155176
textField.keyboardAppearance = isDarkKeyboard ? .dark : .default
156-
if isCursorHidden { textField.tintColor = .clear }
177+
textField.inputView = inputViewForAll
178+
textField.inputAccessoryView = inputAccessoryViewForAll
179+
if isCursorHidden {
180+
textField.tintColor = .clear
181+
} else {
182+
textField.tintColor = tintColor
183+
}
157184
if isBottomLineTextField {
158185
let border = CALayer()
159186
border.name = "bottomBorderLayer"
@@ -200,6 +227,7 @@ public protocol DPOTPViewDelegate {
200227
tapView.addGestureRecognizer(tap)
201228
self.addSubview(tapView)
202229
}
230+
isLoaded = true
203231
}
204232
}
205233

@@ -210,8 +238,14 @@ public protocol DPOTPViewDelegate {
210238
// super.draw(rect)
211239
// }
212240

213-
241+
@discardableResult
214242
open override func becomeFirstResponder() -> Bool {
243+
if arrTextFields.count != count {
244+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
245+
self.becomeFirstResponder()
246+
}
247+
return false
248+
}
215249
if isCursorHidden {
216250
for i in 0 ..< arrTextFields.count {
217251
if arrTextFields[i].text?.count == 0 {
@@ -223,12 +257,13 @@ public protocol DPOTPViewDelegate {
223257
}
224258
}
225259
} else {
226-
_ = arrTextFields[0].becomeFirstResponder()
260+
_ = arrTextFields.first?.becomeFirstResponder()
227261
}
228262
dpOTPViewDelegate?.dpOTPViewBecomeFirstResponder()
229263
return super.becomeFirstResponder()
230264
}
231265

266+
@discardableResult
232267
open override func resignFirstResponder() -> Bool {
233268
arrTextFields.forEach { (textField) in
234269
_ = textField.resignFirstResponder()
@@ -241,7 +276,7 @@ public protocol DPOTPViewDelegate {
241276
_ = self.becomeFirstResponder()
242277
}
243278

244-
func validate() -> Bool {
279+
open func validate() -> Bool {
245280
var isValid = true
246281
arrTextFields.forEach { (textField) in
247282
if Int(textField.text ?? "") == nil {

DPOTPView/DPOTPView/ViewController.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,26 @@ class ViewController: UIViewController {
3838
// txtOTPView.isBottomLineTextField = true
3939
// txtOTPView.isCircleTextField = true
4040
view.addSubview(txtOTPView)
41+
txtOTPView.becomeFirstResponder()
42+
let numberToolbar = UIToolbar(frame:CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
43+
numberToolbar.barStyle = .default
44+
numberToolbar.items = [
45+
UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(cancelNumberPad)),
46+
UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil),
47+
UIBarButtonItem(title: "Done", style: .plain, target: self, action: #selector(doneWithNumberPad))]
48+
numberToolbar.sizeToFit()
49+
txtOTPView.inputAccessoryViewForAll = numberToolbar
50+
51+
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
52+
self.txtOTPView.count = 6
53+
}
4154
}
55+
}
56+
@objc func cancelNumberPad() {
57+
58+
}
59+
@objc func doneWithNumberPad() {
60+
4261
}
4362
override func viewDidAppear(_ animated: Bool) {
4463
super.viewDidAppear(animated)

0 commit comments

Comments
 (0)