Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can set fillcolor and prevent crash on new iOS #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>ASPinCodeField.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>Demo.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
</dict>
</plist>
17 changes: 12 additions & 5 deletions ASPinCodeField/Sources/ASPinCodeField.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
}
Expand Down
1 change: 1 addition & 0 deletions Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down