From 241753e316f628e40dac48eacf20bb4095e67789 Mon Sep 17 00:00:00 2001 From: Jim Boyd Date: Thu, 18 May 2017 16:33:23 -0600 Subject: [PATCH 1/4] Rename state property to viewState. This avoids namespace collision with existing state property in UIControl subclasses implementing PinCodeDigitView. --- .../AppIcon.appiconset/Contents.json | 25 +++++++++++++++++++ Source/PinCodeDigitView.swift | 2 +- Source/PinCodeView.swift | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/PinCodeViewDemo/PinCodeView/Assets.xcassets/AppIcon.appiconset/Contents.json b/PinCodeViewDemo/PinCodeView/Assets.xcassets/AppIcon.appiconset/Contents.json index 36d2c80..1d060ed 100644 --- a/PinCodeViewDemo/PinCodeView/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/PinCodeViewDemo/PinCodeView/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -30,6 +40,16 @@ "size" : "60x60", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", @@ -59,6 +79,11 @@ "idiom" : "ipad", "size" : "76x76", "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" } ], "info" : { diff --git a/Source/PinCodeDigitView.swift b/Source/PinCodeDigitView.swift index 863f5c3..65c164d 100644 --- a/Source/PinCodeDigitView.swift +++ b/Source/PinCodeDigitView.swift @@ -11,7 +11,7 @@ import UIKit public protocol PinCodeDigitView: class { init() var digit: String? { get set } - var state: PinCodeDigitViewState! { get set } + var viewState: PinCodeDigitViewState! { get set } func configure(withState: PinCodeDigitViewState) // hackish way to constraint to UIView only diff --git a/Source/PinCodeView.swift b/Source/PinCodeView.swift index 4096d52..6961ae1 100644 --- a/Source/PinCodeView.swift +++ b/Source/PinCodeView.swift @@ -212,7 +212,7 @@ public class PinCodeView: UIStackView { } for digitView in zelf.digitViews { - digitView.state = .failedVerification + digitView.viewState = .failedVerification } zelf.animateFailure() From 2781584429b531135ff905276f7e69c4654e2f2a Mon Sep 17 00:00:00 2001 From: Jim Boyd Date: Thu, 18 May 2017 16:34:28 -0600 Subject: [PATCH 2/4] Example UITextField implementation of PinCodeDigitView --- .../PinCodeView/PinCodeDigitField.swift | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 PinCodeViewDemo/PinCodeView/PinCodeDigitField.swift diff --git a/PinCodeViewDemo/PinCodeView/PinCodeDigitField.swift b/PinCodeViewDemo/PinCodeView/PinCodeDigitField.swift new file mode 100755 index 0000000..e82d1ac --- /dev/null +++ b/PinCodeViewDemo/PinCodeView/PinCodeDigitField.swift @@ -0,0 +1,67 @@ +// +// PinCodeDigitField.swift +// PinCodeView +// +// Created by Jim Boyd on 05/18/2017. +// Copyright © 2017 Cabosoft. All rights reserved. +// +// Modeled after PinCodeDigitSquareView.swift +// Copyright © 2017 Dapulse. All rights reserved. +// https://github.com/DaPulse/PinCodeView/blob/master/PinCodeViewDemo/PinCodeView/PinCodeDigitSquareView.swift +// + +import UIKit +import PinCodeView + +public class PinCodeDigitField: UITextField, PinCodeDigitView { + + public var viewState: PinCodeDigitViewState! = .empty { + didSet { + if viewState != oldValue { + configure(withState: viewState) + } + } + } + + public var digit: String? { + didSet { + guard digit != oldValue else { return } + self.viewState = digit != nil ? .hasDigit : .empty + self.text = digit + } + } + + convenience required public init() { + self.init(frame: .zero) + + self.isUserInteractionEnabled = false + self.isSecureTextEntry = true + + self.textAlignment = .center + self.font = UIFont.systemFont(ofSize: 30) + self.layer.borderWidth = 3 + self.layer.cornerRadius = 5 + self.layer.masksToBounds = true + + translatesAutoresizingMaskIntoConstraints = false + widthAnchor.constraint(equalToConstant: 40).isActive = true + + self.textColor = UIColor(colorLiteralRed: 51.0 / 255.0, green: 51.0 / 255.0, blue: 51.0 / 255.0, alpha: 1) + self.backgroundColor = UIColor.white + + self.configure(withState: .empty) + } + + public func configure(withState state: PinCodeDigitViewState) { + switch state { + case .empty: + layer.borderColor = UIColor(colorLiteralRed: 202.0 / 255.0, green: 202.0 / 255.0, blue: 202.0 / 255.0, alpha: 1).cgColor + + case .hasDigit: + layer.borderColor = UIColor(colorLiteralRed: 0, green: 161.0 / 255.0, blue: 230.0 / 255.0, alpha: 1).cgColor + + case .failedVerification: + layer.borderColor = UIColor(colorLiteralRed: 246.0 / 255.0, green: 95.0 / 255.0, blue: 124.0 / 255.0, alpha: 1).cgColor + } + } +} From 22aaaff0a43d880cb77bbea71c283b72b111522d Mon Sep 17 00:00:00 2001 From: Jim Boyd Date: Thu, 18 May 2017 16:34:58 -0600 Subject: [PATCH 3/4] Update project to demonstrate PinCodeDigitField --- .../PinCodeView.xcodeproj/project.pbxproj | 4 +++ .../PinCodeView/Base.lproj/Main.storyboard | 35 ++++++++++++++++--- .../PinCodeView/PinCodeDigitSquareView.swift | 8 ++--- .../PinCodeView/ViewController.swift | 12 +++++++ 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/PinCodeViewDemo/PinCodeView.xcodeproj/project.pbxproj b/PinCodeViewDemo/PinCodeView.xcodeproj/project.pbxproj index 607dc0c..d8d6e61 100644 --- a/PinCodeViewDemo/PinCodeView.xcodeproj/project.pbxproj +++ b/PinCodeViewDemo/PinCodeView.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ B07CD5861E90F27100677A5F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B07CD5841E90F27100677A5F /* LaunchScreen.storyboard */; }; B0E13F271E9256AC00A29648 /* PinCodeDigitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0E13F261E9256AC00A29648 /* PinCodeDigitView.swift */; }; B0E13F2B1E925B9A00A29648 /* PinCodeDigitSquareView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0E13F2A1E925B9A00A29648 /* PinCodeDigitSquareView.swift */; }; + B8ED6B4E1ECE553B00D69EB8 /* PinCodeDigitField.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8ED6B4D1ECE553B00D69EB8 /* PinCodeDigitField.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -32,6 +33,7 @@ B07CD5871E90F27100677A5F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; B0E13F261E9256AC00A29648 /* PinCodeDigitView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinCodeDigitView.swift; sourceTree = ""; }; B0E13F2A1E925B9A00A29648 /* PinCodeDigitSquareView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinCodeDigitSquareView.swift; sourceTree = ""; }; + B8ED6B4D1ECE553B00D69EB8 /* PinCodeDigitField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinCodeDigitField.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -79,6 +81,7 @@ B019381E1E918896006D3856 /* Source */, B07CD57B1E90F27100677A5F /* AppDelegate.swift */, B0E13F2A1E925B9A00A29648 /* PinCodeDigitSquareView.swift */, + B8ED6B4D1ECE553B00D69EB8 /* PinCodeDigitField.swift */, B07CD57D1E90F27100677A5F /* ViewController.swift */, B07CD57F1E90F27100677A5F /* Main.storyboard */, B07CD5821E90F27100677A5F /* Assets.xcassets */, @@ -162,6 +165,7 @@ buildActionMask = 2147483647; files = ( B0E13F271E9256AC00A29648 /* PinCodeDigitView.swift in Sources */, + B8ED6B4E1ECE553B00D69EB8 /* PinCodeDigitField.swift in Sources */, B01938291E918896006D3856 /* PinCodeViewDelegate.swift in Sources */, B07CD57E1E90F27100677A5F /* ViewController.swift in Sources */, B07CD57C1E90F27100677A5F /* AppDelegate.swift in Sources */, diff --git a/PinCodeViewDemo/PinCodeView/Base.lproj/Main.storyboard b/PinCodeViewDemo/PinCodeView/Base.lproj/Main.storyboard index c0f63f9..dc81974 100644 --- a/PinCodeViewDemo/PinCodeView/Base.lproj/Main.storyboard +++ b/PinCodeViewDemo/PinCodeView/Base.lproj/Main.storyboard @@ -1,11 +1,11 @@ - + - - + + @@ -22,7 +22,7 @@ - + @@ -42,19 +42,46 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/PinCodeViewDemo/PinCodeView/PinCodeDigitSquareView.swift b/PinCodeViewDemo/PinCodeView/PinCodeDigitSquareView.swift index c7acad7..41393d9 100644 --- a/PinCodeViewDemo/PinCodeView/PinCodeDigitSquareView.swift +++ b/PinCodeViewDemo/PinCodeView/PinCodeDigitSquareView.swift @@ -10,10 +10,10 @@ import UIKit public class PinCodeDigitSquareView: UILabel, PinCodeDigitView { - public var state: PinCodeDigitViewState! = .empty { + public var viewState: PinCodeDigitViewState! = .empty { didSet { - if state != oldValue { - configure(withState: state) + if viewState != oldValue { + configure(withState: viewState) } } } @@ -21,7 +21,7 @@ public class PinCodeDigitSquareView: UILabel, PinCodeDigitView { public var digit: String? { didSet { guard digit != oldValue else { return } - self.state = digit != nil ? .hasDigit : .empty + self.viewState = digit != nil ? .hasDigit : .empty self.text = digit } } diff --git a/PinCodeViewDemo/PinCodeView/ViewController.swift b/PinCodeViewDemo/PinCodeView/ViewController.swift index 44c5a58..afbbde6 100644 --- a/PinCodeViewDemo/PinCodeView/ViewController.swift +++ b/PinCodeViewDemo/PinCodeView/ViewController.swift @@ -19,6 +19,18 @@ class ViewController: UIViewController { pinView.digitViewInit = PinCodeDigitSquareView.init } } + + @IBOutlet weak var pinView2: PinCodeView! { + didSet { + pinView2.delegate = self + pinView2.numberOfDigits = 4 + pinView2.groupingSize = 0 + pinView2.itemSpacing = 10 + pinView2.distribution = .fillEqually + pinView2.digitViewInit = PinCodeDigitField.init + } + } + } extension ViewController: PinCodeViewDelegate { From 0c940d1d0a5f4d694cff83473dc6f035cabc5f49 Mon Sep 17 00:00:00 2001 From: Jim Boyd Date: Fri, 13 Oct 2017 15:48:45 -0600 Subject: [PATCH 4/4] Swift 4 migration / Xcode 9 --- PinCodeView.podspec | 3 ++- PinCodeView.xcodeproj/project.pbxproj | 21 +++++++++++++++--- .../PinCodeView.xcodeproj/project.pbxproj | 19 +++++++++++++--- .../PinCodeView/PinCodeDigitField.swift | 10 ++++----- .../PinCodeView/PinCodeDigitSquareView.swift | 10 ++++----- .../PinCodeView/ViewController.swift | 2 +- Source/PinCodeSeparatorView.swift | 4 ++-- Source/PinCodeView.swift | 22 +++++++++---------- 8 files changed, 60 insertions(+), 31 deletions(-) diff --git a/PinCodeView.podspec b/PinCodeView.podspec index ac839aa..b647952 100644 --- a/PinCodeView.podspec +++ b/PinCodeView.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = "PinCodeView" - s.version = "0.2.0" + s.version = "0.3.0" s.summary = "A drop in view for pin code input" s.description = <<-DESC A drop in view for getting pin code from the user. @@ -20,5 +20,6 @@ Pod::Spec.new do |s| s.platform = :ios, '9.0' s.source = { :git => "https://github.com/dapulse/PinCodeView.git", :tag => s.version.to_s } s.source_files = "Source/", "Source/*.swift" + s.xcconfig = { 'SWIFT_VERSION' => '4.0' } end diff --git a/PinCodeView.xcodeproj/project.pbxproj b/PinCodeView.xcodeproj/project.pbxproj index dfa4eb0..f3af891 100644 --- a/PinCodeView.xcodeproj/project.pbxproj +++ b/PinCodeView.xcodeproj/project.pbxproj @@ -103,7 +103,7 @@ B01937F51E918567006D3856 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0830; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = Dapulse; TargetAttributes = { B01937FD1E918567006D3856 = { @@ -166,7 +166,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -174,7 +176,11 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -204,6 +210,7 @@ SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = ""; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -220,7 +227,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -228,7 +237,11 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -250,6 +263,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = ""; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -273,7 +287,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -292,7 +306,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.dapulse.PinCodeView; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -315,6 +329,7 @@ B01938081E918567006D3856 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/PinCodeViewDemo/PinCodeView.xcodeproj/project.pbxproj b/PinCodeViewDemo/PinCodeView.xcodeproj/project.pbxproj index d8d6e61..d6a8e0c 100644 --- a/PinCodeViewDemo/PinCodeView.xcodeproj/project.pbxproj +++ b/PinCodeViewDemo/PinCodeView.xcodeproj/project.pbxproj @@ -118,12 +118,13 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0830; - LastUpgradeCheck = 0830; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = Dapulse; TargetAttributes = { B07CD5771E90F27100677A5F = { CreatedOnToolsVersion = 8.3; DevelopmentTeam = F92RQULD22; + LastSwiftMigration = 0900; ProvisioningStyle = Automatic; }; }; @@ -207,7 +208,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -215,7 +218,11 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -258,7 +265,9 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -266,7 +275,11 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -302,7 +315,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.dapulse.PinCodeView; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -316,7 +329,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.dapulse.PinCodeView; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/PinCodeViewDemo/PinCodeView/PinCodeDigitField.swift b/PinCodeViewDemo/PinCodeView/PinCodeDigitField.swift index e82d1ac..334c028 100755 --- a/PinCodeViewDemo/PinCodeView/PinCodeDigitField.swift +++ b/PinCodeViewDemo/PinCodeView/PinCodeDigitField.swift @@ -23,7 +23,7 @@ public class PinCodeDigitField: UITextField, PinCodeDigitView { } } - public var digit: String? { + @objc public var digit: String? { didSet { guard digit != oldValue else { return } self.viewState = digit != nil ? .hasDigit : .empty @@ -46,7 +46,7 @@ public class PinCodeDigitField: UITextField, PinCodeDigitView { translatesAutoresizingMaskIntoConstraints = false widthAnchor.constraint(equalToConstant: 40).isActive = true - self.textColor = UIColor(colorLiteralRed: 51.0 / 255.0, green: 51.0 / 255.0, blue: 51.0 / 255.0, alpha: 1) + self.textColor = UIColor(red: 51.0 / 255.0, green: 51.0 / 255.0, blue: 51.0 / 255.0, alpha: 1) self.backgroundColor = UIColor.white self.configure(withState: .empty) @@ -55,13 +55,13 @@ public class PinCodeDigitField: UITextField, PinCodeDigitView { public func configure(withState state: PinCodeDigitViewState) { switch state { case .empty: - layer.borderColor = UIColor(colorLiteralRed: 202.0 / 255.0, green: 202.0 / 255.0, blue: 202.0 / 255.0, alpha: 1).cgColor + layer.borderColor = UIColor(red: 202.0 / 255.0, green: 202.0 / 255.0, blue: 202.0 / 255.0, alpha: 1).cgColor case .hasDigit: - layer.borderColor = UIColor(colorLiteralRed: 0, green: 161.0 / 255.0, blue: 230.0 / 255.0, alpha: 1).cgColor + layer.borderColor = UIColor(red: 0, green: 161.0 / 255.0, blue: 230.0 / 255.0, alpha: 1).cgColor case .failedVerification: - layer.borderColor = UIColor(colorLiteralRed: 246.0 / 255.0, green: 95.0 / 255.0, blue: 124.0 / 255.0, alpha: 1).cgColor + layer.borderColor = UIColor(red: 246.0 / 255.0, green: 95.0 / 255.0, blue: 124.0 / 255.0, alpha: 1).cgColor } } } diff --git a/PinCodeViewDemo/PinCodeView/PinCodeDigitSquareView.swift b/PinCodeViewDemo/PinCodeView/PinCodeDigitSquareView.swift index 41393d9..f22a989 100644 --- a/PinCodeViewDemo/PinCodeView/PinCodeDigitSquareView.swift +++ b/PinCodeViewDemo/PinCodeView/PinCodeDigitSquareView.swift @@ -18,7 +18,7 @@ public class PinCodeDigitSquareView: UILabel, PinCodeDigitView { } } - public var digit: String? { + @objc public var digit: String? { didSet { guard digit != oldValue else { return } self.viewState = digit != nil ? .hasDigit : .empty @@ -33,7 +33,7 @@ public class PinCodeDigitSquareView: UILabel, PinCodeDigitView { self.font = UIFont.systemFont(ofSize: 30) self.layer.borderWidth = 2 self.layer.cornerRadius = 3 - self.textColor = UIColor(colorLiteralRed: 51.0/255.0, green: 51.0/255.0, blue: 51.0/255.0, alpha: 1) + self.textColor = UIColor(red: 51.0/255.0, green: 51.0/255.0, blue: 51.0/255.0, alpha: 1) self.configure(withState: .empty) translatesAutoresizingMaskIntoConstraints = false @@ -43,13 +43,13 @@ public class PinCodeDigitSquareView: UILabel, PinCodeDigitView { public func configure(withState state: PinCodeDigitViewState) { switch state { case .empty: - layer.borderColor = UIColor(colorLiteralRed: 151.0/255.0, green: 151.0/255.0, blue: 151.0/255.0, alpha: 1).cgColor + layer.borderColor = UIColor(red: 151.0/255.0, green: 151.0/255.0, blue: 151.0/255.0, alpha: 1).cgColor case .hasDigit: - layer.borderColor = UIColor(colorLiteralRed: 0, green: 161.0/255.0, blue: 230.0/255.0, alpha: 1).cgColor + layer.borderColor = UIColor(red: 0, green: 161.0/255.0, blue: 230.0/255.0, alpha: 1).cgColor case .failedVerification: - layer.borderColor = UIColor(colorLiteralRed: 246.0/255.0, green: 95.0/255.0, blue: 124.0/255.0, alpha: 1).cgColor + layer.borderColor = UIColor(red: 246.0/255.0, green: 95.0/255.0, blue: 124.0/255.0, alpha: 1).cgColor } } } diff --git a/PinCodeViewDemo/PinCodeView/ViewController.swift b/PinCodeViewDemo/PinCodeView/ViewController.swift index afbbde6..53a1528 100644 --- a/PinCodeViewDemo/PinCodeView/ViewController.swift +++ b/PinCodeViewDemo/PinCodeView/ViewController.swift @@ -34,7 +34,7 @@ class ViewController: UIViewController { } extension ViewController: PinCodeViewDelegate { - func pinCodeView(_ view: PinCodeView, didSubmitPinCode code: String, isValidCallback callback: @escaping (Bool) -> Void) { + @objc func pinCodeView(_ view: PinCodeView, didSubmitPinCode code: String, isValidCallback callback: @escaping (Bool) -> Void) { view.alpha = 0.5 diff --git a/Source/PinCodeSeparatorView.swift b/Source/PinCodeSeparatorView.swift index f759830..e11c64e 100644 --- a/Source/PinCodeSeparatorView.swift +++ b/Source/PinCodeSeparatorView.swift @@ -10,12 +10,12 @@ import UIKit class PinCodeSeparatorView: UILabel { - init(text: String) { + @objc init(text: String) { super.init(frame: .zero) self.text = text self.font = UIFont.systemFont(ofSize: 30) self.textAlignment = .center - self.setContentHuggingPriority(UILayoutPriorityRequired, for: .horizontal) + self.setContentHuggingPriority(UILayoutPriority.required, for: .horizontal) self.sizeToFit() } diff --git a/Source/PinCodeView.swift b/Source/PinCodeView.swift index 6961ae1..4e5ed0d 100644 --- a/Source/PinCodeView.swift +++ b/Source/PinCodeView.swift @@ -48,21 +48,21 @@ public class PinCodeView: UIStackView { public var textType: TextType = .numbers /// initializer for the single digit views - public var digitViewInit: ((Void) -> PinCodeDigitView)! + public var digitViewInit: (() -> PinCodeDigitView)! /// pretty straightforward - public var numberOfDigits: Int = 6 + @objc public var numberOfDigits: Int = 6 /// group size for separating digits /// for example: /// group size of 3 will give ___ - ___ - public var groupingSize: Int = 3 + @objc public var groupingSize: Int = 3 /// space between items - public var itemSpacing: Int = 2 + @objc public var itemSpacing: Int = 2 private var previousDigitState: State? - public var isEnabled: Bool { + @objc public var isEnabled: Bool { get { return digitState != .disabled } set { if newValue == isEnabled { return } @@ -161,12 +161,12 @@ public class PinCodeView: UIStackView { } } - func didTap() { + @objc func didTap() { guard !self.isFirstResponder else { return } becomeFirstResponder() } - func didLongPress(gesture: UILongPressGestureRecognizer) { + @objc func didLongPress(gesture: UILongPressGestureRecognizer) { guard gesture.state == .began else { return } if !self.isFirstResponder { @@ -184,11 +184,11 @@ public class PinCodeView: UIStackView { }) } - public func resetDigits() { + @objc public func resetDigits() { digitState = .inserting(0) } - func clearText() { + @objc func clearText() { for digitView in digitViews { digitView.digit = nil } @@ -198,7 +198,7 @@ public class PinCodeView: UIStackView { return [.loading, .disabled].contains(digitState) == false } - func submitDigits() { + @objc func submitDigits() { digitState = .loading delegate?.pinCodeView(self, didSubmitPinCode: text, isValidCallback: { [weak self] (isValid) in @@ -243,7 +243,7 @@ extension PinCodeView { } let index = text.index(text.startIndex, offsetBy: min(numberOfDigits, text.characters.count)) - insertText(text.substring(to: index)) + insertText(String(text[..