Skip to content

Commit

Permalink
Add secure entry mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Fawxy committed Jan 30, 2018
1 parent 99fdb6c commit 67d0f5a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions CBPinEntryView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

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

s.description = <<-DESC
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+.
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+.
DESC

s.homepage = 'https://github.com/Fawxy/CBPinEntryView'
Expand Down
10 changes: 9 additions & 1 deletion CBPinEntryView/Classes/CBPinEntryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public protocol CBPinEntryViewDelegate: class {
}
}

@IBInspectable open var isSecure: Bool = CBPinEntryViewDefaults.isSecure

@IBInspectable open var secureCharacter: String = CBPinEntryViewDefaults.secureCharacter

private var stackView: UIStackView?
private var textField: UITextField!

Expand Down Expand Up @@ -264,7 +268,11 @@ extension CBPinEntryView: UITextFieldDelegate {
if button.tag == newLength {
button.layer.borderColor = entryDefaultBorderColour.cgColor
UIView.setAnimationsEnabled(false)
button.setTitle(string, for: .normal)
if !isSecure {
button.setTitle(string, for: .normal)
} else {
button.setTitle(secureCharacter, for: .normal)
}
UIView.setAnimationsEnabled(true)
} else if button.tag == newLength + 1 {
button.layer.borderColor = entryBorderColour.cgColor
Expand Down
4 changes: 4 additions & 0 deletions CBPinEntryView/Classes/CBPinEntryViewDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ struct CBPinEntryViewDefaults {

// Default font for entry fields
static let entryFont: UIFont = UIFont.systemFont(ofSize: 16)

static let isSecure: Bool = false

static let secureCharacter: String = ""
}
Binary file added Example/.DS_Store
Binary file not shown.
12 changes: 7 additions & 5 deletions Example/CBPinEntryView/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<device id="retina4_0" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -38,19 +39,20 @@
<userDefinedRuntimeAttribute type="color" keyPath="entryDefaultBorderColour">
<color key="value" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="boolean" keyPath="isSecure" value="YES"/>
</userDefinedRuntimeAttributes>
</view>
<stackView opaque="NO" contentMode="scaleToFill" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="l00-Oi-KOV">
<rect key="frame" x="100" y="192" width="120" height="20.5"/>
<rect key="frame" x="100.5" y="192" width="119.5" height="20.5"/>
<subviews>
<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">
<rect key="frame" x="0.0" y="0.0" width="105.5" height="20.5"/>
<rect key="frame" x="0.0" y="0.0" width="105" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<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">
<rect key="frame" x="109.5" y="0.0" width="10.5" height="20.5"/>
<rect key="frame" x="109" y="0.0" width="10.5" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![License](https://img.shields.io/cocoapods/l/CBPinEntryView.svg?style=flat)](http://cocoapods.org/pods/CBPinEntryView)
[![Platform](https://img.shields.io/cocoapods/p/CBPinEntryView.svg?style=flat)](http://cocoapods.org/pods/CBPinEntryView)

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.
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!

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

Expand All @@ -22,7 +22,7 @@ pod "CBPinEntryView"
```
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.

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

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.

Expand Down

0 comments on commit 67d0f5a

Please sign in to comment.