Skip to content

Commit

Permalink
#3 add Background color for the filled textField
Browse files Browse the repository at this point in the history
  • Loading branch information
Datt1994 committed Jul 5, 2020
1 parent 7f63ed5 commit da6e704
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
12 changes: 7 additions & 5 deletions DPOTPView/DPOTPView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1120;
LastUpgradeCheck = 1120;
LastUpgradeCheck = 1140;
ORGANIZATIONNAME = datt;
TargetAttributes = {
C6604BEA247B2037005F402D = {
Expand Down Expand Up @@ -289,7 +289,7 @@
C6604BF5247B2037005F402D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
Expand Down Expand Up @@ -321,7 +321,7 @@
C6604BF6247B2037005F402D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
Expand Down Expand Up @@ -471,13 +471,14 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = 3Y587YMRM5;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = DPOTPView/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1;
PRODUCT_BUNDLE_IDENTIFIER = "com.datt.DPOTPView-example";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -493,13 +494,14 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = 3Y587YMRM5;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = DPOTPView/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1;
PRODUCT_BUNDLE_IDENTIFIER = "com.datt.DPOTPView-example";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Binary file not shown.
3 changes: 3 additions & 0 deletions DPOTPView/DPOTPView/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
<userDefinedRuntimeAttribute type="color" keyPath="backGroundColorTextField">
<color key="value" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="backGroundColorFilledTextField">
<color key="value" red="0.50196078430000002" green="0.14117647059999999" blue="0.59999999999999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="XWD-DZ-vzi" customClass="DPOTPView" customModule="DPOTPView_Example" customModuleProvider="target">
Expand Down
18 changes: 15 additions & 3 deletions DPOTPView/DPOTPView/DPOTPView/DPOTPView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public protocol DPOTPViewDelegate {
/** Background color for the textField */
@IBInspectable open dynamic var backGroundColorTextField: UIColor = UIColor.clear

/** Background color for the filled textField */
@IBInspectable open dynamic var backGroundColorFilledTextField: UIColor?

/** Border color for the TextField */
@IBInspectable open dynamic var borderColorTextField: UIColor?

Expand Down Expand Up @@ -146,7 +149,7 @@ public protocol DPOTPViewDelegate {
textField.borderStyle = .none
textField.tag = i * 1000
textField.tintColor = tintColorTextField
textField.layer.backgroundColor = backGroundColorTextField.cgColor
textField.backgroundColor = backGroundColorTextField
textField.isSecureTextEntry = isSecureTextEntry
textField.font = fontTextField
textField.keyboardAppearance = isDarkKeyboard ? .dark : .default
Expand Down Expand Up @@ -285,10 +288,19 @@ protocol OTPBackTextFieldDelegate {
}


class OTPBackTextField: UITextField {
fileprivate class OTPBackTextField: UITextField {

var OTPBackDelegate : OTPBackTextFieldDelegate?
weak var dpOTPView : DPOTPView!
override var text: String? {
didSet {
if text?.isEmpty ?? true {
self.backgroundColor = dpOTPView.backGroundColorTextField
} else {
self.backgroundColor = dpOTPView.backGroundColorFilledTextField ?? dpOTPView.backGroundColorTextField
}
}
}

override func deleteBackward() {
super.deleteBackward()
Expand Down Expand Up @@ -383,7 +395,7 @@ class OTPBackTextField: UITextField {
}


extension String {
fileprivate extension String {
subscript(_ i: Int) -> String {
let idx1 = index(startIndex, offsetBy: i)
let idx2 = index(idx1, offsetBy: 1)
Expand Down

0 comments on commit da6e704

Please sign in to comment.