Skip to content

Commit

Permalink
1.5.12 Background image support, #9 Reload on rest count, #8 InputAcc…
Browse files Browse the repository at this point in the history
…essoryView Support and #5 issue solved
  • Loading branch information
Datt1994 committed Jul 29, 2021
1 parent 33ad4f5 commit 950ecde
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 19 deletions.
Binary file removed DPOTPView.framework.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion DPOTPView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "DPOTPView"
s.version = "1.5.11"
s.version = "1.5.12"
s.summary = "Customisable OTP view and Passcode view."

# This description is used to generate tags and improve search results.
Expand Down
Binary file added DPOTPView.xcframework.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions DPOTPView/DPOTPView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.5.11;
MARKETING_VERSION = 1.5.12;
PRODUCT_BUNDLE_IDENTIFIER = com.datt.DPOTPView;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -337,7 +337,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.5.11;
MARKETING_VERSION = 1.5.12;
PRODUCT_BUNDLE_IDENTIFIER = com.datt.DPOTPView;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Binary file not shown.
45 changes: 35 additions & 10 deletions DPOTPView/DPOTPView/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17505"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -43,7 +44,7 @@
<integer key="value" value="4"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="backGroundColorTextField">
<color key="value" systemColor="systemGreenColor" red="0.20392156859999999" green="0.78039215689999997" blue="0.34901960780000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="value" systemColor="systemGreenColor"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="boolean" keyPath="isSecureTextEntry" value="YES"/>
<userDefinedRuntimeAttribute type="boolean" keyPath="isCircleTextField" value="YES"/>
Expand All @@ -57,6 +58,7 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="XZU-8o-pmY" customClass="DPOTPView" customModule="DPOTPView_Example" customModuleProvider="target">
<rect key="frame" x="82" y="54" width="250" height="60"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="tintColor" systemColor="systemBlueColor"/>
<constraints>
<constraint firstAttribute="width" constant="250" id="cZB-G0-hzf"/>
<constraint firstAttribute="height" constant="60" id="wRP-4J-J9f"/>
Expand Down Expand Up @@ -115,17 +117,17 @@
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="boolean" keyPath="dismissOnLastEntry" value="YES"/>
<userDefinedRuntimeAttribute type="color" keyPath="selectedBorderColorTextField">
<color key="value" systemColor="systemPinkColor" red="1" green="0.1764705882" blue="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="value" systemColor="systemPinkColor"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="backGroundColorTextField">
<color key="value" systemColor="systemTealColor" red="0.35294117650000001" green="0.7843137255" blue="0.98039215690000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="value" systemColor="systemTealColor"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="boolean" keyPath="isDarkKeyboard" value="YES"/>
<userDefinedRuntimeAttribute type="number" keyPath="selectedBorderWidthTextField">
<real key="value" value="3"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="placeholderTextColor">
<color key="value" systemColor="systemRedColor" red="1" green="0.23137254900000001" blue="0.18823529410000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="value" systemColor="systemRedColor"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="string" keyPath="placeholder" value="✲✻✵✫✱✶"/>
<userDefinedRuntimeAttribute type="number" keyPath="shadowRadiusTextField">
Expand All @@ -135,7 +137,7 @@
<real key="value" value="0.5"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="shadowColorTextField">
<color key="value" systemColor="systemPinkColor" red="1" green="0.1764705882" blue="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="value" systemColor="systemPinkColor"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="size" keyPath="shadowOffsetSizeTextField">
<size key="value" width="0.0" height="0.0"/>
Expand All @@ -145,6 +147,7 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="DtP-Ci-7qP" customClass="DPOTPView" customModule="DPOTPView_Example" customModuleProvider="target">
<rect key="frame" x="69.5" y="234" width="275" height="50"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="tintColor" systemColor="systemOrangeColor"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="fUH-Ah-GwS"/>
<constraint firstAttribute="width" constant="275" id="la5-1V-b37"/>
Expand All @@ -161,12 +164,13 @@
<real key="value" value="3"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="selectedBorderColorTextField">
<color key="value" systemColor="systemRedColor" red="1" green="0.23137254900000001" blue="0.18823529410000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="value" systemColor="systemRedColor"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="boolean" keyPath="dismissOnLastEntry" value="YES"/>
<userDefinedRuntimeAttribute type="number" keyPath="selectedBorderWidthTextField">
<real key="value" value="4"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="image" keyPath="backGroundImageTextField" value="globe" catalog="system"/>
</userDefinedRuntimeAttributes>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="tOx-qg-TIm" customClass="DPOTPView" customModule="DPOTPView_Example" customModuleProvider="target">
Expand All @@ -187,7 +191,7 @@
<real key="value" value="2"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="selectedBorderColorTextField">
<color key="value" systemColor="systemGreenColor" red="0.20392156859999999" green="0.78039215689999997" blue="0.34901960780000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="value" systemColor="systemGreenColor"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="boolean" keyPath="isSecureTextEntry" value="YES"/>
<userDefinedRuntimeAttribute type="boolean" keyPath="dismissOnLastEntry" value="YES"/>
Expand All @@ -201,6 +205,7 @@
</userDefinedRuntimeAttributes>
</view>
</subviews>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="XWD-DZ-vzi" firstAttribute="top" secondItem="XZU-8o-pmY" secondAttribute="bottom" constant="30" id="Cti-JR-mBU"/>
Expand All @@ -214,7 +219,6 @@
<constraint firstItem="XWD-DZ-vzi" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="pZ6-Tt-3LK"/>
<constraint firstItem="tOx-qg-TIm" firstAttribute="top" secondItem="DtP-Ci-7qP" secondAttribute="bottom" constant="30" id="qPi-Iv-UFP"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
<connections>
<outlet property="txtDPOTPView" destination="Mzr-7d-8hs" id="r5V-17-dtd"/>
Expand All @@ -225,4 +229,25 @@
<point key="canvasLocation" x="131.8840579710145" y="118.52678571428571"/>
</scene>
</scenes>
<resources>
<image name="globe" catalog="system" width="128" height="121"/>
<systemColor name="systemBlueColor">
<color red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemGreenColor">
<color red="0.20392156862745098" green="0.7803921568627451" blue="0.34901960784313724" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemOrangeColor">
<color red="1" green="0.58431372549019611" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemPinkColor">
<color red="1" green="0.17647058823529413" blue="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemRedColor">
<color red="1" green="0.23137254901960785" blue="0.18823529411764706" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemTealColor">
<color red="0.35294117647058826" green="0.78431372549019607" blue="0.98039215686274506" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
47 changes: 41 additions & 6 deletions DPOTPView/DPOTPView/DPOTPView/DPOTPView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ public protocol DPOTPViewDelegate {
@IBDesignable open class DPOTPView: UIView {

/** The number of textField that will be put in the DPOTPView */
@IBInspectable open dynamic var count: Int = 4
@IBInspectable open dynamic var count: Int = 4 {
didSet {
if isLoaded {
isLoaded = false
let isFirstResponder = arrTextFields.filter({$0.isFirstResponder}).first != nil
initialization()
if isFirstResponder {
becomeFirstResponder()
}
}
}
}

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

/** Background Image for all textFields */
@IBInspectable open dynamic var backGroundImageTextField: UIImage?

/** Background color for the textField */
@IBInspectable open dynamic var backGroundColorTextField: UIColor = UIColor.clear

Expand Down Expand Up @@ -93,6 +107,9 @@ public protocol DPOTPViewDelegate {
open dynamic var textEdgeInsets : UIEdgeInsets?
open dynamic var editingTextEdgeInsets : UIEdgeInsets?

open dynamic var inputViewForAll: UIView?
open dynamic var inputAccessoryViewForAll: UIView?

open dynamic var dpOTPViewDelegate : DPOTPViewDelegate?
open dynamic var keyboardType:UIKeyboardType = UIKeyboardType.asciiCapableNumberPad

Expand All @@ -114,6 +131,7 @@ public protocol DPOTPViewDelegate {
}

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

func initialization() {
if arrTextFields.count != 0 { return }
if isLoaded { return }
arrTextFields.forEach{ $0.removeFromSuperview() }
arrTextFields = []

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

Expand All @@ -150,10 +170,17 @@ public protocol DPOTPViewDelegate {
textField.tag = i * 1000
textField.tintColor = tintColorTextField
textField.backgroundColor = backGroundColorTextField
textField.background = backGroundImageTextField
textField.isSecureTextEntry = isSecureTextEntry
textField.font = fontTextField
textField.keyboardAppearance = isDarkKeyboard ? .dark : .default
if isCursorHidden { textField.tintColor = .clear }
textField.inputView = inputViewForAll
textField.inputAccessoryView = inputAccessoryViewForAll
if isCursorHidden {
textField.tintColor = .clear
} else {
textField.tintColor = tintColor
}
if isBottomLineTextField {
let border = CALayer()
border.name = "bottomBorderLayer"
Expand Down Expand Up @@ -200,6 +227,7 @@ public protocol DPOTPViewDelegate {
tapView.addGestureRecognizer(tap)
self.addSubview(tapView)
}
isLoaded = true
}
}

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


@discardableResult
open override func becomeFirstResponder() -> Bool {
if arrTextFields.count != count {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.becomeFirstResponder()
}
return false
}
if isCursorHidden {
for i in 0 ..< arrTextFields.count {
if arrTextFields[i].text?.count == 0 {
Expand All @@ -223,12 +257,13 @@ public protocol DPOTPViewDelegate {
}
}
} else {
_ = arrTextFields[0].becomeFirstResponder()
_ = arrTextFields.first?.becomeFirstResponder()
}
dpOTPViewDelegate?.dpOTPViewBecomeFirstResponder()
return super.becomeFirstResponder()
}

@discardableResult
open override func resignFirstResponder() -> Bool {
arrTextFields.forEach { (textField) in
_ = textField.resignFirstResponder()
Expand All @@ -241,7 +276,7 @@ public protocol DPOTPViewDelegate {
_ = self.becomeFirstResponder()
}

func validate() -> Bool {
open func validate() -> Bool {
var isValid = true
arrTextFields.forEach { (textField) in
if Int(textField.text ?? "") == nil {
Expand Down
19 changes: 19 additions & 0 deletions DPOTPView/DPOTPView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,26 @@ class ViewController: UIViewController {
// txtOTPView.isBottomLineTextField = true
// txtOTPView.isCircleTextField = true
view.addSubview(txtOTPView)
txtOTPView.becomeFirstResponder()
let numberToolbar = UIToolbar(frame:CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
numberToolbar.barStyle = .default
numberToolbar.items = [
UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(cancelNumberPad)),
UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil),
UIBarButtonItem(title: "Done", style: .plain, target: self, action: #selector(doneWithNumberPad))]
numberToolbar.sizeToFit()
txtOTPView.inputAccessoryViewForAll = numberToolbar

DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
self.txtOTPView.count = 6
}
}
}
@objc func cancelNumberPad() {

}
@objc func doneWithNumberPad() {

}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
Expand Down

0 comments on commit 950ecde

Please sign in to comment.