Skip to content

Commit 67d0f5a

Browse files
committed
Add secure entry mode
1 parent 99fdb6c commit 67d0f5a

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed

CBPinEntryView.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'CBPinEntryView'
11-
s.version = '1.5.0'
11+
s.version = '1.5.1'
1212
s.summary = 'A view for entering arbitrary length numerical pins or codes written in Swift 4.0.'
1313

1414
# This description is used to generate tags and improve search results.
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
1818
# * Finally, don't worry about the indent, CocoaPods strips it!
1919

2020
s.description = <<-DESC
21-
This view allows a user to enter a pin or code (for security/mobile verification etc) of any length. It allows deletion, continuation and allows you to get the entire entered code as a single String or Int without having to join Strings from multiple text fields. It's fast, looks nice (I think) and is customisable! Requires iOS 9+.
21+
This view allows a user to enter a pin or code (for security/mobile verification etc) of any length. It allows deletion, continuation, secure entry, and allows you to get the entire entered code as a single String or Int without having to join Strings from multiple text fields. It's fast, looks nice (I think) and is customisable! Requires iOS 9+.
2222
DESC
2323

2424
s.homepage = 'https://github.com/Fawxy/CBPinEntryView'

CBPinEntryView/Classes/CBPinEntryView.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public protocol CBPinEntryViewDelegate: class {
7474
}
7575
}
7676

77+
@IBInspectable open var isSecure: Bool = CBPinEntryViewDefaults.isSecure
78+
79+
@IBInspectable open var secureCharacter: String = CBPinEntryViewDefaults.secureCharacter
80+
7781
private var stackView: UIStackView?
7882
private var textField: UITextField!
7983

@@ -264,7 +268,11 @@ extension CBPinEntryView: UITextFieldDelegate {
264268
if button.tag == newLength {
265269
button.layer.borderColor = entryDefaultBorderColour.cgColor
266270
UIView.setAnimationsEnabled(false)
267-
button.setTitle(string, for: .normal)
271+
if !isSecure {
272+
button.setTitle(string, for: .normal)
273+
} else {
274+
button.setTitle(secureCharacter, for: .normal)
275+
}
268276
UIView.setAnimationsEnabled(true)
269277
} else if button.tag == newLength + 1 {
270278
button.layer.borderColor = entryBorderColour.cgColor

CBPinEntryView/Classes/CBPinEntryViewDefaults.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@ struct CBPinEntryViewDefaults {
3636

3737
// Default font for entry fields
3838
static let entryFont: UIFont = UIFont.systemFont(ofSize: 16)
39+
40+
static let isSecure: Bool = false
41+
42+
static let secureCharacter: String = ""
3943
}

Example/.DS_Store

6 KB
Binary file not shown.

Example/CBPinEntryView/Base.lproj/Main.storyboard

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
33
<device id="retina4_0" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
7-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
89
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
910
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1011
</dependencies>
@@ -38,19 +39,20 @@
3839
<userDefinedRuntimeAttribute type="color" keyPath="entryDefaultBorderColour">
3940
<color key="value" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
4041
</userDefinedRuntimeAttribute>
42+
<userDefinedRuntimeAttribute type="boolean" keyPath="isSecure" value="YES"/>
4143
</userDefinedRuntimeAttributes>
4244
</view>
4345
<stackView opaque="NO" contentMode="scaleToFill" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="l00-Oi-KOV">
44-
<rect key="frame" x="100" y="192" width="120" height="20.5"/>
46+
<rect key="frame" x="100.5" y="192" width="119.5" height="20.5"/>
4547
<subviews>
4648
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="String output:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Xwt-zJ-aIh">
47-
<rect key="frame" x="0.0" y="0.0" width="105.5" height="20.5"/>
49+
<rect key="frame" x="0.0" y="0.0" width="105" height="20.5"/>
4850
<fontDescription key="fontDescription" type="system" pointSize="17"/>
4951
<nil key="textColor"/>
5052
<nil key="highlightedColor"/>
5153
</label>
5254
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pjq-79-3tQ">
53-
<rect key="frame" x="109.5" y="0.0" width="10.5" height="20.5"/>
55+
<rect key="frame" x="109" y="0.0" width="10.5" height="20.5"/>
5456
<fontDescription key="fontDescription" type="system" pointSize="17"/>
5557
<nil key="textColor"/>
5658
<nil key="highlightedColor"/>

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![License](https://img.shields.io/cocoapods/l/CBPinEntryView.svg?style=flat)](http://cocoapods.org/pods/CBPinEntryView)
55
[![Platform](https://img.shields.io/cocoapods/p/CBPinEntryView.svg?style=flat)](http://cocoapods.org/pods/CBPinEntryView)
66

7-
CBPinEntryView is a view written in Swift to allow easy and slick entry of pins or codes. It allows backspacing, dismissal of keyboard and continuation, the whole code is given as a single String or Int and the view is very easily customisable in code or the storyboard.
7+
CBPinEntryView is a view written in Swift to allow easy and slick entry of pins or codes. It allows backspacing, dismissal of keyboard and continuation, the whole code is given as a single String or Int and the view is very easily customisable in code or the storyboard. Now with secure entry option!
88

99
<img src='http://i.imgur.com/dAdUVkp.gif' alt='Showing easy entry and deletion' width='350'>
1010

@@ -22,7 +22,7 @@ pod "CBPinEntryView"
2222
```
2323
Put a view into your storyboard or xib and set it's class to `CBPinEntryView`. Create an outlet in your file and customise either with the IBInspectable properties or in your code.
2424

25-
Get the code with either `entryView.getPinAsString()` or `entryView.getPinAsInt()`.
25+
Get the code with either `entryView.getPinAsString()` or `entryView.getPinAsInt()`. Secure entry with customisable secure character (change from ● to ✱ or any other character).
2626

2727
There is now also an error mode which can be toggled with `entryView.toggleError()`. It is automatically removed if the user taps on the field or starts typing again.
2828

0 commit comments

Comments
 (0)