diff --git a/OTPFieldView.xcodeproj/project.xcworkspace/xcuserdata/momina.abbasi.xcuserdatad/UserInterfaceState.xcuserstate b/OTPFieldView.xcodeproj/project.xcworkspace/xcuserdata/momina.abbasi.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..8d36f8c Binary files /dev/null and b/OTPFieldView.xcodeproj/project.xcworkspace/xcuserdata/momina.abbasi.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/OTPFieldView.xcodeproj/xcuserdata/momina.abbasi.xcuserdatad/xcschemes/xcschememanagement.plist b/OTPFieldView.xcodeproj/xcuserdata/momina.abbasi.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..261e774 --- /dev/null +++ b/OTPFieldView.xcodeproj/xcuserdata/momina.abbasi.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + OTPFieldView.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/OTPFieldView/OTPFieldView.swift b/OTPFieldView/OTPFieldView.swift index bcee25d..8cf2680 100644 --- a/OTPFieldView/OTPFieldView.swift +++ b/OTPFieldView/OTPFieldView.swift @@ -341,3 +341,28 @@ extension OTPFieldView: UITextFieldDelegate { calculateEnteredOTPSTring(isDeleted: true) } } +extension OTPFieldView { + public func clearAllTextFields() { + // Iterate through all OTP text fields and clear their text + for index in stride(from: 0, to: fieldsCount, by: 1) { + if let otpField = viewWithTag(index + 1) as? OTPTextField { + otpField.text = "" + secureEntryData[index] = "" + + // Reset background and border colors to default + if displayType == .diamond || displayType == .underlinedBottom { + if let shapeLayer = otpField.shapeLayer { + shapeLayer.fillColor = defaultBackgroundColor.cgColor + shapeLayer.strokeColor = defaultBorderColor.cgColor + } + } else { + otpField.backgroundColor = defaultBackgroundColor + otpField.layer.borderColor = defaultBorderColor.cgColor + } + } else { + // Handle case when otpField is not found (optional) + print("Warning: OTP field with tag \(index + 1) not found.") + } + } + } +}