Skip to content

Commit 91bbd44

Browse files
committed
Updated README.md
1 parent b3904f6 commit 91bbd44

File tree

4 files changed

+111
-16
lines changed

4 files changed

+111
-16
lines changed

README.md

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,76 @@
1-
# PasscodeView
2-
iOS Simple Passcode View
1+
# SimplePasscodeView
2+
3+
![GitHub](https://img.shields.io/badge/pod-v0.0.2-blue.svg) ![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg) ![GitHub](https://img.shields.io/badge/platform-iOS-orange.svg)
4+
5+
A Protocol-Oreinted Passcode component provides you with the flexibility of easy integration in your application and customization.
6+
7+
It allows both alphanumerics and emoji entry as passcode.
8+
9+
## How it works
10+
11+
<img src="//i.imgur.com/A1PzUT7.gif" width="200"> <img src="//i.imgur.com/CMNph39.gif" width="200">
12+
13+
## Usage
14+
### Via Cocoapods
15+
16+
1. Add to your podfile:
17+
18+
`pod 'SimplePasscodeView'`
19+
20+
2. In Terminal, navigate to your project folder, then:
21+
22+
`pod update`
23+
24+
`pod install`
25+
26+
First, import SimplePasscodeView and then declare passcodeView as a IBOutlet property:
27+
28+
```swift
29+
import SimplePasscodeView
30+
31+
class ViewController: UIViewController {
32+
@IBOutlet weak var passcode: SimplePasscodeView!
33+
override func viewDidLoad() {
34+
super.viewDidLoad()
35+
passcodeView.delegate = self
36+
}
37+
}
38+
39+
extension ViewController: SimplePasscodeDelegate {
40+
func didFinishEntering(_ passcode: String) {
41+
//Do whatever you want
42+
}
43+
}
44+
```
45+
46+
Drag and drop a `UIView` in your `xib` or `storyboard` and assign the custom class to `SimplePasscodeView`. Follow the steps below:
47+
48+
<img src="//i.imgur.com/qJGsSHT.gif">
49+
50+
## Customizable Properties
51+
52+
- length - Pin length that is required. The empty circles will be rendered based on this
53+
- defaultSpacing - Spacing between each circle/pin.
54+
- secureEntry - Masking the entry either secure or not-secure.
55+
- pinfillColor - The color to fill when pin entry is received.( only for secure entry )
56+
- pinborderColor - The border color for the circular indicator.
57+
- pinfont - Font for pin text that is entered.( only if not secure entry )
58+
59+
Other customizable properties available.
60+
61+
### Contributing
62+
63+
- **Star the repo if you would like to follow future updates**
64+
65+
- **Please feel free to fork the repo and raise a pull request :)**
66+
67+
## Contact
68+
69+
- For any queries drop an email to '**[email protected]**'
70+
71+
- You can hire me if you need help with any mobile related work.
72+
73+
## Thanks
74+
75+
Available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
76+

SimplePasscodeView.podspec

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
Pod::Spec.new do |spec|
22
spec.name = "SimplePasscodeView"
3-
spec.version = "0.0.1"
3+
spec.version = "0.0.2"
44
spec.license = { :type => 'MIT' }
55
spec.homepage = "https://github.com/vkrmchowdary/PasscodeView"
66
spec.author = { "Geeko Coco" => "[email protected]" }
77
spec.summary = "A Passcode component for iOS"
88
spec.description = <<-DESC
99
SimplePasscodeView mimics iOS Passcode behaviour with more customizable options and can be easily integrated into any project.
1010
DESC
11-
spec.source = { :git => "https://github.com/vkrmchowdary/PasscodeView.git", :tag => spec.version.to_s}
12-
spec.source_files = 'SimplePasscodeView/PasscodeView/*'
11+
12+
spec.ios.deployment_target = '11.0'
13+
spec.swift_version = '4.1'
14+
15+
spec.source = { :git => "https://github.com/vkrmchowdary/PasscodeView.git", :tag => 'v0.0.2'}
16+
spec.source_files = 'SimplePasscodeView/PasscodeView/*.swift', 'SimplePasscodeView/PasscodeView/*.xib'
1317
spec.ios.framework = 'UIKit'
1418
end

SimplePasscodeView/PasscodeView/SimplePasscodeView.swift

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import UIKit
99

1010
public protocol SimplePasscodeDelegate: class {
1111
func didFinishEntering(_ passcode: String)
12+
func didDeleteBackward()
1213
}
1314

1415
public class SimplePasscodeView: UIView {
1516

1617
@IBOutlet private weak var passcodeStackView: UIStackView!
1718

1819
private var contentView: UIView?
19-
private var passscodeText = String()
20+
private var passcodeText = String()
2021

2122
public weak var delegate: SimplePasscodeDelegate?
2223
public var keyboardType: UIKeyboardType = .default
@@ -76,6 +77,15 @@ extension SimplePasscodeView: PasscodeConfigurable {
7677
}
7778
return views
7879
}
80+
81+
public func clear() {
82+
passcodeStackView.arrangedSubviews.forEach { (view) in
83+
if let pinView = view as? PinView {
84+
pinView.update(fill: false, andText: nil, isSecureEntry: isSecureEntry)
85+
}
86+
}
87+
passcodeText.removeAll()
88+
}
7989
}
8090

8191
extension SimplePasscodeView: UIKeyInput {
@@ -89,12 +99,12 @@ extension SimplePasscodeView: UIKeyInput {
8999
}
90100

91101
public var hasText: Bool {
92-
return !passscodeText.isEmpty
102+
return !passcodeText.isEmpty
93103
}
94104

95105
public func insertText(_ text: String) {
96106
guard canInsertCharacters() else { return }
97-
passscodeText.append(text)
107+
passcodeText.append(text)
98108

99109
guard let view = passcodeStackView.arrangedSubviews.filter({ (view) -> Bool in
100110
if let pinView = view as? PinView,
@@ -106,14 +116,16 @@ extension SimplePasscodeView: UIKeyInput {
106116

107117
view.update(fill: true, andText: text, isSecureEntry: isSecureEntry)
108118

109-
if passscodeText.count == length {
110-
delegate?.didFinishEntering(passscodeText)
119+
if passcodeText.count == length {
120+
delegate?.didFinishEntering(passcodeText)
111121
}
112122
}
113123

114124
public func deleteBackward() {
115125
guard hasText else { return }
116-
passscodeText.removeLast()
126+
127+
passcodeText.removeLast()
128+
delegate?.didDeleteBackward()
117129

118130
guard let view = passcodeStackView.arrangedSubviews.filter({ (view) -> Bool in
119131
if let pinView = view as? PinView,
@@ -127,6 +139,6 @@ extension SimplePasscodeView: UIKeyInput {
127139
}
128140

129141
private func canInsertCharacters() -> Bool {
130-
return passscodeText.count != length
142+
return passcodeText.count != length
131143
}
132144
}

SimplePasscodeView/ViewController.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@ class ViewController: UIViewController {
1414
super.viewDidLoad()
1515
// Do any additional setup after loading the view, typically from a nib.
1616
passcodeView.delegate = self
17-
passcodeView.pinfillColor = UIColor.green
18-
passcodeView.isSecureEntry = false
19-
passcodeView.pinfont = UIFont.boldSystemFont(ofSize: 25)
20-
passcodeView.pinfontColor = UIColor.blue
2117
}
2218
}
2319

2420
extension ViewController: SimplePasscodeDelegate {
21+
func didDeleteBackward() {
22+
//Do whatever you want
23+
}
24+
2525
func didFinishEntering(_ passcode: String) {
26+
//Do whatever you want
2627
print("passcode: \(passcode)")
28+
let alert = UIAlertController(title: "Passcode", message: passcode, preferredStyle: .alert)
29+
let alertAction = UIAlertAction(title: "Ok", style: .cancel, handler: nil)
30+
alert.addAction(alertAction)
31+
present(alert, animated: true, completion: nil)
2732
}
2833
}
2934

0 commit comments

Comments
 (0)