diff --git a/ASPinCodeField.xcodeproj/project.xcworkspace/xcuserdata/narongritkanhanoi.xcuserdatad/UserInterfaceState.xcuserstate b/ASPinCodeField.xcodeproj/project.xcworkspace/xcuserdata/narongritkanhanoi.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..27ed11e Binary files /dev/null and b/ASPinCodeField.xcodeproj/project.xcworkspace/xcuserdata/narongritkanhanoi.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ASPinCodeField.xcodeproj/xcuserdata/narongritkanhanoi.xcuserdatad/xcschemes/xcschememanagement.plist b/ASPinCodeField.xcodeproj/xcuserdata/narongritkanhanoi.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..8b9d04a --- /dev/null +++ b/ASPinCodeField.xcodeproj/xcuserdata/narongritkanhanoi.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,19 @@ + + + + + SchemeUserState + + ASPinCodeField.xcscheme_^#shared#^_ + + orderHint + 0 + + Demo.xcscheme_^#shared#^_ + + orderHint + 1 + + + + diff --git a/ASPinCodeField/Sources/ASPinCodeField.swift b/ASPinCodeField/Sources/ASPinCodeField.swift old mode 100644 new mode 100755 index 0df7041..0e66ee4 --- a/ASPinCodeField/Sources/ASPinCodeField.swift +++ b/ASPinCodeField/Sources/ASPinCodeField.swift @@ -63,7 +63,13 @@ public final class ASPinCodeField: UIControl, UIKeyInput { self._inputAccessoryView = newValue } } - + + public var fillColor: UIColor = .white { + didSet { + digitsView.forEach { $0.layer.backgroundColor = fillColor.cgColor } + } + } + public var textColor: UIColor = .black { didSet { digitsView.forEach { $0.label.textColor = textColor } @@ -147,6 +153,8 @@ public final class ASPinCodeField: UIControl, UIKeyInput { digitView.label.font = textFont digitView.layer.borderColor = borderColor.cgColor digitView.layer.cornerRadius = cornerRadius + digitView.layer.backgroundColor = fillColor.cgColor + digitsView.append(digitView) self.stackView.addArrangedSubview(digitView) } @@ -182,10 +190,9 @@ public final class ASPinCodeField: UIControl, UIKeyInput { assertionFailure("DataSource property is not set") return true } - - if self.digitsView.count <= numberOfDigits { - self.digitsView[digits.count].state = .focus - } + + digits = "" + self.digitsView[0].state = .focus return super.becomeFirstResponder() } diff --git a/Demo/ViewController.swift b/Demo/ViewController.swift index 05455fe..992a65c 100644 --- a/Demo/ViewController.swift +++ b/Demo/ViewController.swift @@ -17,6 +17,7 @@ class ViewController: UIViewController, ASPinCodeFieldDelegate, ASPinCodeFieldDa @IBOutlet weak var storyboardPinField: ASPinCodeField! { didSet { + storyboardPinField.fillColor = UIColor.orange storyboardPinField.delegate = self storyboardPinField.dataSource = self storyboardPinField.borderColor = UIColor.lightGray diff --git a/README.md b/README.md index e8b1376..1f82bd2 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ pinCodeView.textColor = UIColor.black pinCodeView.cornerRadius = 4 pinCodeView.itemsSpacing = 8 pinCodeView.textFont = .boldSystemFont(ofSize: 20) +pinCodeView.fillColor = UIColor.orange ``` Delegate and DataSource