├── Demo └── PinCodeView.gif ├── LICENSE.md ├── PinCodeView.podspec ├── PinCodeView.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── ariel.xcuserdatad │ └── xcschemes │ ├── PinCodeView.xcscheme │ └── xcschememanagement.plist ├── PinCodeViewDemo ├── .gitignore ├── PinCodeView.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcuserdata │ │ └── ariel.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ ├── PinCodeView.xcscheme │ │ └── xcschememanagement.plist ├── PinCodeView.xcworkspace │ └── contents.xcworkspacedata ├── PinCodeView │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ ├── PinCodeDigitSquareView.swift │ └── ViewController.swift ├── Podfile └── Podfile.lock ├── README.md └── Source ├── PinCodeView ├── Info.plist ├── PinCodeDigitView.swift ├── PinCodeSeparatorView.swift ├── PinCodeView.h ├── PinCodeView.swift └── PinCodeViewDelegate.swift └── RxSwift └── PinCodeView+Rx.swift /Demo/PinCodeView.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arielpollack/PinCodeView/587a209163dc1b45fd6e645e93f57d6f13e06d8f/Demo/PinCodeView.gif -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 daPulse LTD 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /PinCodeView.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint PinCodeView.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | s.name = "PinCodeView" 11 | s.version = "0.3.0" 12 | s.summary = "A drop in view for pin code input" 13 | s.description = <<-DESC 14 | A drop in view for getting pin code from the user. 15 | Main use case is input for codes received in SMS/email etc. 16 | DESC 17 | s.homepage = "http://www.github.com/arielpollack/PinCodeView" 18 | s.license = { :type => "MIT", :file => "LICENSE.md" } 19 | s.author = { "Ariel Pollack" => "pollack.ariel@gmail.com" } 20 | s.platform = :ios, '9.0' 21 | s.source = { :git => "https://github.com/arielpollack/PinCodeView.git", :tag => s.version.to_s } 22 | s.default_subspec = "Core" 23 | s.swift_version = '4.0' 24 | 25 | s.subspec "Core" do |ss| 26 | ss.source_files = "Source/PinCodeView/" 27 | ss.framework = "Foundation" 28 | end 29 | 30 | s.subspec "RxSwift" do |ss| 31 | ss.source_files = "Source/RxSwift/" 32 | ss.dependency "PinCodeView/Core" 33 | ss.dependency "RxSwift" 34 | ss.dependency "RxCocoa" 35 | end 36 | 37 | end 38 | -------------------------------------------------------------------------------- /PinCodeView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B0AF130C207253330052E7A4 /* PinCodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0AF1306207253330052E7A4 /* PinCodeView.swift */; }; 11 | B0AF130D207253330052E7A4 /* PinCodeViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0AF1307207253330052E7A4 /* PinCodeViewDelegate.swift */; }; 12 | B0AF130E207253330052E7A4 /* PinCodeSeparatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0AF1308207253330052E7A4 /* PinCodeSeparatorView.swift */; }; 13 | B0AF130F207253330052E7A4 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B0AF1309207253330052E7A4 /* Info.plist */; }; 14 | B0AF1310207253330052E7A4 /* PinCodeDigitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0AF130A207253330052E7A4 /* PinCodeDigitView.swift */; }; 15 | B0AF1311207253330052E7A4 /* PinCodeView.h in Headers */ = {isa = PBXBuildFile; fileRef = B0AF130B207253330052E7A4 /* PinCodeView.h */; settings = {ATTRIBUTES = (Public, ); }; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | B01937FE1E918567006D3856 /* PinCodeView.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PinCodeView.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | B0AF1306207253330052E7A4 /* PinCodeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PinCodeView.swift; path = PinCodeView/PinCodeView.swift; sourceTree = ""; }; 21 | B0AF1307207253330052E7A4 /* PinCodeViewDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PinCodeViewDelegate.swift; path = PinCodeView/PinCodeViewDelegate.swift; sourceTree = ""; }; 22 | B0AF1308207253330052E7A4 /* PinCodeSeparatorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PinCodeSeparatorView.swift; path = PinCodeView/PinCodeSeparatorView.swift; sourceTree = ""; }; 23 | B0AF1309207253330052E7A4 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = PinCodeView/Info.plist; sourceTree = ""; }; 24 | B0AF130A207253330052E7A4 /* PinCodeDigitView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PinCodeDigitView.swift; path = PinCodeView/PinCodeDigitView.swift; sourceTree = ""; }; 25 | B0AF130B207253330052E7A4 /* PinCodeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PinCodeView.h; path = PinCodeView/PinCodeView.h; sourceTree = ""; }; 26 | /* End PBXFileReference section */ 27 | 28 | /* Begin PBXFrameworksBuildPhase section */ 29 | B01937FA1E918567006D3856 /* Frameworks */ = { 30 | isa = PBXFrameworksBuildPhase; 31 | buildActionMask = 2147483647; 32 | files = ( 33 | ); 34 | runOnlyForDeploymentPostprocessing = 0; 35 | }; 36 | /* End PBXFrameworksBuildPhase section */ 37 | 38 | /* Begin PBXGroup section */ 39 | B01937F41E918567006D3856 = { 40 | isa = PBXGroup; 41 | children = ( 42 | B01938111E918716006D3856 /* Source */, 43 | B01937FF1E918567006D3856 /* Products */, 44 | ); 45 | sourceTree = ""; 46 | }; 47 | B01937FF1E918567006D3856 /* Products */ = { 48 | isa = PBXGroup; 49 | children = ( 50 | B01937FE1E918567006D3856 /* PinCodeView.framework */, 51 | ); 52 | name = Products; 53 | sourceTree = ""; 54 | }; 55 | B01938111E918716006D3856 /* Source */ = { 56 | isa = PBXGroup; 57 | children = ( 58 | B0AF1309207253330052E7A4 /* Info.plist */, 59 | B0AF130A207253330052E7A4 /* PinCodeDigitView.swift */, 60 | B0AF1308207253330052E7A4 /* PinCodeSeparatorView.swift */, 61 | B0AF130B207253330052E7A4 /* PinCodeView.h */, 62 | B0AF1306207253330052E7A4 /* PinCodeView.swift */, 63 | B0AF1307207253330052E7A4 /* PinCodeViewDelegate.swift */, 64 | ); 65 | path = Source; 66 | sourceTree = ""; 67 | }; 68 | /* End PBXGroup section */ 69 | 70 | /* Begin PBXHeadersBuildPhase section */ 71 | B01937FB1E918567006D3856 /* Headers */ = { 72 | isa = PBXHeadersBuildPhase; 73 | buildActionMask = 2147483647; 74 | files = ( 75 | B0AF1311207253330052E7A4 /* PinCodeView.h in Headers */, 76 | ); 77 | runOnlyForDeploymentPostprocessing = 0; 78 | }; 79 | /* End PBXHeadersBuildPhase section */ 80 | 81 | /* Begin PBXNativeTarget section */ 82 | B01937FD1E918567006D3856 /* PinCodeView */ = { 83 | isa = PBXNativeTarget; 84 | buildConfigurationList = B01938061E918567006D3856 /* Build configuration list for PBXNativeTarget "PinCodeView" */; 85 | buildPhases = ( 86 | B01937F91E918567006D3856 /* Sources */, 87 | B01937FA1E918567006D3856 /* Frameworks */, 88 | B01937FB1E918567006D3856 /* Headers */, 89 | B01937FC1E918567006D3856 /* Resources */, 90 | ); 91 | buildRules = ( 92 | ); 93 | dependencies = ( 94 | ); 95 | name = PinCodeView; 96 | productName = PinCodeView; 97 | productReference = B01937FE1E918567006D3856 /* PinCodeView.framework */; 98 | productType = "com.apple.product-type.framework"; 99 | }; 100 | /* End PBXNativeTarget section */ 101 | 102 | /* Begin PBXProject section */ 103 | B01937F51E918567006D3856 /* Project object */ = { 104 | isa = PBXProject; 105 | attributes = { 106 | LastUpgradeCheck = 0830; 107 | ORGANIZATIONNAME = Dapulse; 108 | TargetAttributes = { 109 | B01937FD1E918567006D3856 = { 110 | CreatedOnToolsVersion = 8.3; 111 | LastSwiftMigration = 0920; 112 | ProvisioningStyle = Automatic; 113 | }; 114 | }; 115 | }; 116 | buildConfigurationList = B01937F81E918567006D3856 /* Build configuration list for PBXProject "PinCodeView" */; 117 | compatibilityVersion = "Xcode 3.2"; 118 | developmentRegion = English; 119 | hasScannedForEncodings = 0; 120 | knownRegions = ( 121 | en, 122 | ); 123 | mainGroup = B01937F41E918567006D3856; 124 | productRefGroup = B01937FF1E918567006D3856 /* Products */; 125 | projectDirPath = ""; 126 | projectRoot = ""; 127 | targets = ( 128 | B01937FD1E918567006D3856 /* PinCodeView */, 129 | ); 130 | }; 131 | /* End PBXProject section */ 132 | 133 | /* Begin PBXResourcesBuildPhase section */ 134 | B01937FC1E918567006D3856 /* Resources */ = { 135 | isa = PBXResourcesBuildPhase; 136 | buildActionMask = 2147483647; 137 | files = ( 138 | B0AF130F207253330052E7A4 /* Info.plist in Resources */, 139 | ); 140 | runOnlyForDeploymentPostprocessing = 0; 141 | }; 142 | /* End PBXResourcesBuildPhase section */ 143 | 144 | /* Begin PBXSourcesBuildPhase section */ 145 | B01937F91E918567006D3856 /* Sources */ = { 146 | isa = PBXSourcesBuildPhase; 147 | buildActionMask = 2147483647; 148 | files = ( 149 | B0AF130D207253330052E7A4 /* PinCodeViewDelegate.swift in Sources */, 150 | B0AF130C207253330052E7A4 /* PinCodeView.swift in Sources */, 151 | B0AF130E207253330052E7A4 /* PinCodeSeparatorView.swift in Sources */, 152 | B0AF1310207253330052E7A4 /* PinCodeDigitView.swift in Sources */, 153 | ); 154 | runOnlyForDeploymentPostprocessing = 0; 155 | }; 156 | /* End PBXSourcesBuildPhase section */ 157 | 158 | /* Begin XCBuildConfiguration section */ 159 | B01938041E918567006D3856 /* Debug */ = { 160 | isa = XCBuildConfiguration; 161 | buildSettings = { 162 | ALWAYS_SEARCH_USER_PATHS = NO; 163 | CLANG_ANALYZER_NONNULL = YES; 164 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 165 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 166 | CLANG_CXX_LIBRARY = "libc++"; 167 | CLANG_ENABLE_MODULES = YES; 168 | CLANG_ENABLE_OBJC_ARC = YES; 169 | CLANG_WARN_BOOL_CONVERSION = YES; 170 | CLANG_WARN_CONSTANT_CONVERSION = YES; 171 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 172 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 173 | CLANG_WARN_EMPTY_BODY = YES; 174 | CLANG_WARN_ENUM_CONVERSION = YES; 175 | CLANG_WARN_INFINITE_RECURSION = YES; 176 | CLANG_WARN_INT_CONVERSION = YES; 177 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 178 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 179 | CLANG_WARN_UNREACHABLE_CODE = YES; 180 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 181 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 182 | COPY_PHASE_STRIP = NO; 183 | CURRENT_PROJECT_VERSION = 1; 184 | DEBUG_INFORMATION_FORMAT = dwarf; 185 | ENABLE_STRICT_OBJC_MSGSEND = YES; 186 | ENABLE_TESTABILITY = YES; 187 | GCC_C_LANGUAGE_STANDARD = gnu99; 188 | GCC_DYNAMIC_NO_PIC = NO; 189 | GCC_NO_COMMON_BLOCKS = YES; 190 | GCC_OPTIMIZATION_LEVEL = 0; 191 | GCC_PREPROCESSOR_DEFINITIONS = ( 192 | "DEBUG=1", 193 | "$(inherited)", 194 | ); 195 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 196 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 197 | GCC_WARN_UNDECLARED_SELECTOR = YES; 198 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 199 | GCC_WARN_UNUSED_FUNCTION = YES; 200 | GCC_WARN_UNUSED_VARIABLE = YES; 201 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 202 | MTL_ENABLE_DEBUG_INFO = YES; 203 | ONLY_ACTIVE_ARCH = YES; 204 | SDKROOT = iphoneos; 205 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 206 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 207 | TARGETED_DEVICE_FAMILY = "1,2"; 208 | VERSIONING_SYSTEM = "apple-generic"; 209 | VERSION_INFO_PREFIX = ""; 210 | }; 211 | name = Debug; 212 | }; 213 | B01938051E918567006D3856 /* Release */ = { 214 | isa = XCBuildConfiguration; 215 | buildSettings = { 216 | ALWAYS_SEARCH_USER_PATHS = NO; 217 | CLANG_ANALYZER_NONNULL = YES; 218 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 219 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 220 | CLANG_CXX_LIBRARY = "libc++"; 221 | CLANG_ENABLE_MODULES = YES; 222 | CLANG_ENABLE_OBJC_ARC = YES; 223 | CLANG_WARN_BOOL_CONVERSION = YES; 224 | CLANG_WARN_CONSTANT_CONVERSION = YES; 225 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 226 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 227 | CLANG_WARN_EMPTY_BODY = YES; 228 | CLANG_WARN_ENUM_CONVERSION = YES; 229 | CLANG_WARN_INFINITE_RECURSION = YES; 230 | CLANG_WARN_INT_CONVERSION = YES; 231 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 232 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 233 | CLANG_WARN_UNREACHABLE_CODE = YES; 234 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 235 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 236 | COPY_PHASE_STRIP = NO; 237 | CURRENT_PROJECT_VERSION = 1; 238 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 239 | ENABLE_NS_ASSERTIONS = NO; 240 | ENABLE_STRICT_OBJC_MSGSEND = YES; 241 | GCC_C_LANGUAGE_STANDARD = gnu99; 242 | GCC_NO_COMMON_BLOCKS = YES; 243 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 244 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 245 | GCC_WARN_UNDECLARED_SELECTOR = YES; 246 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 247 | GCC_WARN_UNUSED_FUNCTION = YES; 248 | GCC_WARN_UNUSED_VARIABLE = YES; 249 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 250 | MTL_ENABLE_DEBUG_INFO = NO; 251 | SDKROOT = iphoneos; 252 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 253 | TARGETED_DEVICE_FAMILY = "1,2"; 254 | VALIDATE_PRODUCT = YES; 255 | VERSIONING_SYSTEM = "apple-generic"; 256 | VERSION_INFO_PREFIX = ""; 257 | }; 258 | name = Release; 259 | }; 260 | B01938071E918567006D3856 /* Debug */ = { 261 | isa = XCBuildConfiguration; 262 | buildSettings = { 263 | CLANG_ENABLE_MODULES = YES; 264 | CODE_SIGN_IDENTITY = ""; 265 | DEFINES_MODULE = YES; 266 | DYLIB_COMPATIBILITY_VERSION = 1; 267 | DYLIB_CURRENT_VERSION = 1; 268 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 269 | INFOPLIST_FILE = "$(SRCROOT)/Source/PinCodeView/Info.plist"; 270 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 271 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 272 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 273 | PRODUCT_BUNDLE_IDENTIFIER = com.dapulse.PinCodeView; 274 | PRODUCT_NAME = "$(TARGET_NAME)"; 275 | SKIP_INSTALL = YES; 276 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 277 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 278 | SWIFT_VERSION = 4.0; 279 | }; 280 | name = Debug; 281 | }; 282 | B01938081E918567006D3856 /* Release */ = { 283 | isa = XCBuildConfiguration; 284 | buildSettings = { 285 | CLANG_ENABLE_MODULES = YES; 286 | CODE_SIGN_IDENTITY = ""; 287 | DEFINES_MODULE = YES; 288 | DYLIB_COMPATIBILITY_VERSION = 1; 289 | DYLIB_CURRENT_VERSION = 1; 290 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 291 | INFOPLIST_FILE = "$(SRCROOT)/Source/PinCodeView/Info.plist"; 292 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 293 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 294 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 295 | PRODUCT_BUNDLE_IDENTIFIER = com.dapulse.PinCodeView; 296 | PRODUCT_NAME = "$(TARGET_NAME)"; 297 | SKIP_INSTALL = YES; 298 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 299 | SWIFT_VERSION = 4.0; 300 | }; 301 | name = Release; 302 | }; 303 | /* End XCBuildConfiguration section */ 304 | 305 | /* Begin XCConfigurationList section */ 306 | B01937F81E918567006D3856 /* Build configuration list for PBXProject "PinCodeView" */ = { 307 | isa = XCConfigurationList; 308 | buildConfigurations = ( 309 | B01938041E918567006D3856 /* Debug */, 310 | B01938051E918567006D3856 /* Release */, 311 | ); 312 | defaultConfigurationIsVisible = 0; 313 | defaultConfigurationName = Release; 314 | }; 315 | B01938061E918567006D3856 /* Build configuration list for PBXNativeTarget "PinCodeView" */ = { 316 | isa = XCConfigurationList; 317 | buildConfigurations = ( 318 | B01938071E918567006D3856 /* Debug */, 319 | B01938081E918567006D3856 /* Release */, 320 | ); 321 | defaultConfigurationIsVisible = 0; 322 | defaultConfigurationName = Release; 323 | }; 324 | /* End XCConfigurationList section */ 325 | }; 326 | rootObject = B01937F51E918567006D3856 /* Project object */; 327 | } 328 | -------------------------------------------------------------------------------- /PinCodeView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /PinCodeView.xcodeproj/xcuserdata/ariel.xcuserdatad/xcschemes/PinCodeView.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /PinCodeView.xcodeproj/xcuserdata/ariel.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | PinCodeView.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | B01937FD1E918567006D3856 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /PinCodeViewDemo/.gitignore: -------------------------------------------------------------------------------- 1 | Pods 2 | -------------------------------------------------------------------------------- /PinCodeViewDemo/PinCodeView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 8896CC99BE55FE656BF4CBDD /* Pods_PinCodeView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 46C3D0B4D5C649616FF868BD /* Pods_PinCodeView.framework */; }; 11 | B07CD57C1E90F27100677A5F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B07CD57B1E90F27100677A5F /* AppDelegate.swift */; }; 12 | B07CD57E1E90F27100677A5F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B07CD57D1E90F27100677A5F /* ViewController.swift */; }; 13 | B07CD5811E90F27100677A5F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B07CD57F1E90F27100677A5F /* Main.storyboard */; }; 14 | B07CD5831E90F27100677A5F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B07CD5821E90F27100677A5F /* Assets.xcassets */; }; 15 | B07CD5861E90F27100677A5F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B07CD5841E90F27100677A5F /* LaunchScreen.storyboard */; }; 16 | B0E13F2B1E925B9A00A29648 /* PinCodeDigitSquareView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0E13F2A1E925B9A00A29648 /* PinCodeDigitSquareView.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 2D68B860216C714BB51FBFBF /* Pods-PinCodeView.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PinCodeView.release.xcconfig"; path = "Pods/Target Support Files/Pods-PinCodeView/Pods-PinCodeView.release.xcconfig"; sourceTree = ""; }; 21 | 46C3D0B4D5C649616FF868BD /* Pods_PinCodeView.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PinCodeView.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | B07CD5781E90F27100677A5F /* PinCodeViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PinCodeViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | B07CD57B1E90F27100677A5F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 24 | B07CD57D1E90F27100677A5F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 25 | B07CD5801E90F27100677A5F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 26 | B07CD5821E90F27100677A5F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 27 | B07CD5851E90F27100677A5F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 28 | B07CD5871E90F27100677A5F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 29 | B0E13F2A1E925B9A00A29648 /* PinCodeDigitSquareView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinCodeDigitSquareView.swift; sourceTree = ""; }; 30 | EB883BD39A38AD64FC8C661E /* Pods-PinCodeView.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PinCodeView.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PinCodeView/Pods-PinCodeView.debug.xcconfig"; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | B07CD5751E90F27100677A5F /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | 8896CC99BE55FE656BF4CBDD /* Pods_PinCodeView.framework in Frameworks */, 39 | ); 40 | runOnlyForDeploymentPostprocessing = 0; 41 | }; 42 | /* End PBXFrameworksBuildPhase section */ 43 | 44 | /* Begin PBXGroup section */ 45 | 55D14690824047A539F88F75 /* Pods */ = { 46 | isa = PBXGroup; 47 | children = ( 48 | EB883BD39A38AD64FC8C661E /* Pods-PinCodeView.debug.xcconfig */, 49 | 2D68B860216C714BB51FBFBF /* Pods-PinCodeView.release.xcconfig */, 50 | ); 51 | name = Pods; 52 | sourceTree = ""; 53 | }; 54 | B07CD56F1E90F27100677A5F = { 55 | isa = PBXGroup; 56 | children = ( 57 | B07CD57A1E90F27100677A5F /* PinCodeView */, 58 | B07CD5791E90F27100677A5F /* Products */, 59 | 55D14690824047A539F88F75 /* Pods */, 60 | F8B531EE866848D35D392A15 /* Frameworks */, 61 | ); 62 | sourceTree = ""; 63 | }; 64 | B07CD5791E90F27100677A5F /* Products */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | B07CD5781E90F27100677A5F /* PinCodeViewDemo.app */, 68 | ); 69 | name = Products; 70 | sourceTree = ""; 71 | }; 72 | B07CD57A1E90F27100677A5F /* PinCodeView */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | B07CD57B1E90F27100677A5F /* AppDelegate.swift */, 76 | B0E13F2A1E925B9A00A29648 /* PinCodeDigitSquareView.swift */, 77 | B07CD57D1E90F27100677A5F /* ViewController.swift */, 78 | B07CD57F1E90F27100677A5F /* Main.storyboard */, 79 | B07CD5821E90F27100677A5F /* Assets.xcassets */, 80 | B07CD5841E90F27100677A5F /* LaunchScreen.storyboard */, 81 | B07CD5871E90F27100677A5F /* Info.plist */, 82 | ); 83 | path = PinCodeView; 84 | sourceTree = ""; 85 | }; 86 | F8B531EE866848D35D392A15 /* Frameworks */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 46C3D0B4D5C649616FF868BD /* Pods_PinCodeView.framework */, 90 | ); 91 | name = Frameworks; 92 | sourceTree = ""; 93 | }; 94 | /* End PBXGroup section */ 95 | 96 | /* Begin PBXNativeTarget section */ 97 | B07CD5771E90F27100677A5F /* PinCodeViewDemo */ = { 98 | isa = PBXNativeTarget; 99 | buildConfigurationList = B07CD58A1E90F27100677A5F /* Build configuration list for PBXNativeTarget "PinCodeViewDemo" */; 100 | buildPhases = ( 101 | 6086FAF87A80861A9C0533ED /* [CP] Check Pods Manifest.lock */, 102 | B07CD5741E90F27100677A5F /* Sources */, 103 | B07CD5751E90F27100677A5F /* Frameworks */, 104 | B07CD5761E90F27100677A5F /* Resources */, 105 | 0D2EF0E673123CB73BB15EC3 /* [CP] Embed Pods Frameworks */, 106 | 768146AFEDA9DBBDA859172D /* [CP] Copy Pods Resources */, 107 | ); 108 | buildRules = ( 109 | ); 110 | dependencies = ( 111 | ); 112 | name = PinCodeViewDemo; 113 | productName = PinCodeView; 114 | productReference = B07CD5781E90F27100677A5F /* PinCodeViewDemo.app */; 115 | productType = "com.apple.product-type.application"; 116 | }; 117 | /* End PBXNativeTarget section */ 118 | 119 | /* Begin PBXProject section */ 120 | B07CD5701E90F27100677A5F /* Project object */ = { 121 | isa = PBXProject; 122 | attributes = { 123 | LastSwiftUpdateCheck = 0830; 124 | LastUpgradeCheck = 0920; 125 | ORGANIZATIONNAME = Dapulse; 126 | TargetAttributes = { 127 | B07CD5771E90F27100677A5F = { 128 | CreatedOnToolsVersion = 8.3; 129 | DevelopmentTeam = F92RQULD22; 130 | LastSwiftMigration = 0920; 131 | ProvisioningStyle = Automatic; 132 | }; 133 | }; 134 | }; 135 | buildConfigurationList = B07CD5731E90F27100677A5F /* Build configuration list for PBXProject "PinCodeView" */; 136 | compatibilityVersion = "Xcode 3.2"; 137 | developmentRegion = English; 138 | hasScannedForEncodings = 0; 139 | knownRegions = ( 140 | en, 141 | Base, 142 | ); 143 | mainGroup = B07CD56F1E90F27100677A5F; 144 | productRefGroup = B07CD5791E90F27100677A5F /* Products */; 145 | projectDirPath = ""; 146 | projectRoot = ""; 147 | targets = ( 148 | B07CD5771E90F27100677A5F /* PinCodeViewDemo */, 149 | ); 150 | }; 151 | /* End PBXProject section */ 152 | 153 | /* Begin PBXResourcesBuildPhase section */ 154 | B07CD5761E90F27100677A5F /* Resources */ = { 155 | isa = PBXResourcesBuildPhase; 156 | buildActionMask = 2147483647; 157 | files = ( 158 | B07CD5861E90F27100677A5F /* LaunchScreen.storyboard in Resources */, 159 | B07CD5831E90F27100677A5F /* Assets.xcassets in Resources */, 160 | B07CD5811E90F27100677A5F /* Main.storyboard in Resources */, 161 | ); 162 | runOnlyForDeploymentPostprocessing = 0; 163 | }; 164 | /* End PBXResourcesBuildPhase section */ 165 | 166 | /* Begin PBXShellScriptBuildPhase section */ 167 | 0D2EF0E673123CB73BB15EC3 /* [CP] Embed Pods Frameworks */ = { 168 | isa = PBXShellScriptBuildPhase; 169 | buildActionMask = 2147483647; 170 | files = ( 171 | ); 172 | inputPaths = ( 173 | "${SRCROOT}/Pods/Target Support Files/Pods-PinCodeView/Pods-PinCodeView-frameworks.sh", 174 | "${BUILT_PRODUCTS_DIR}/PinCodeView/PinCodeView.framework", 175 | "${BUILT_PRODUCTS_DIR}/RxCocoa/RxCocoa.framework", 176 | "${BUILT_PRODUCTS_DIR}/RxSwift/RxSwift.framework", 177 | ); 178 | name = "[CP] Embed Pods Frameworks"; 179 | outputPaths = ( 180 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PinCodeView.framework", 181 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RxCocoa.framework", 182 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RxSwift.framework", 183 | ); 184 | runOnlyForDeploymentPostprocessing = 0; 185 | shellPath = /bin/sh; 186 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PinCodeView/Pods-PinCodeView-frameworks.sh\"\n"; 187 | showEnvVarsInLog = 0; 188 | }; 189 | 6086FAF87A80861A9C0533ED /* [CP] Check Pods Manifest.lock */ = { 190 | isa = PBXShellScriptBuildPhase; 191 | buildActionMask = 2147483647; 192 | files = ( 193 | ); 194 | inputPaths = ( 195 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 196 | "${PODS_ROOT}/Manifest.lock", 197 | ); 198 | name = "[CP] Check Pods Manifest.lock"; 199 | outputPaths = ( 200 | "$(DERIVED_FILE_DIR)/Pods-PinCodeView-checkManifestLockResult.txt", 201 | ); 202 | runOnlyForDeploymentPostprocessing = 0; 203 | shellPath = /bin/sh; 204 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 205 | showEnvVarsInLog = 0; 206 | }; 207 | 768146AFEDA9DBBDA859172D /* [CP] Copy Pods Resources */ = { 208 | isa = PBXShellScriptBuildPhase; 209 | buildActionMask = 2147483647; 210 | files = ( 211 | ); 212 | inputPaths = ( 213 | ); 214 | name = "[CP] Copy Pods Resources"; 215 | outputPaths = ( 216 | ); 217 | runOnlyForDeploymentPostprocessing = 0; 218 | shellPath = /bin/sh; 219 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PinCodeView/Pods-PinCodeView-resources.sh\"\n"; 220 | showEnvVarsInLog = 0; 221 | }; 222 | /* End PBXShellScriptBuildPhase section */ 223 | 224 | /* Begin PBXSourcesBuildPhase section */ 225 | B07CD5741E90F27100677A5F /* Sources */ = { 226 | isa = PBXSourcesBuildPhase; 227 | buildActionMask = 2147483647; 228 | files = ( 229 | B07CD57E1E90F27100677A5F /* ViewController.swift in Sources */, 230 | B07CD57C1E90F27100677A5F /* AppDelegate.swift in Sources */, 231 | B0E13F2B1E925B9A00A29648 /* PinCodeDigitSquareView.swift in Sources */, 232 | ); 233 | runOnlyForDeploymentPostprocessing = 0; 234 | }; 235 | /* End PBXSourcesBuildPhase section */ 236 | 237 | /* Begin PBXVariantGroup section */ 238 | B07CD57F1E90F27100677A5F /* Main.storyboard */ = { 239 | isa = PBXVariantGroup; 240 | children = ( 241 | B07CD5801E90F27100677A5F /* Base */, 242 | ); 243 | name = Main.storyboard; 244 | sourceTree = ""; 245 | }; 246 | B07CD5841E90F27100677A5F /* LaunchScreen.storyboard */ = { 247 | isa = PBXVariantGroup; 248 | children = ( 249 | B07CD5851E90F27100677A5F /* Base */, 250 | ); 251 | name = LaunchScreen.storyboard; 252 | sourceTree = ""; 253 | }; 254 | /* End PBXVariantGroup section */ 255 | 256 | /* Begin XCBuildConfiguration section */ 257 | B07CD5881E90F27100677A5F /* Debug */ = { 258 | isa = XCBuildConfiguration; 259 | buildSettings = { 260 | ALWAYS_SEARCH_USER_PATHS = NO; 261 | CLANG_ANALYZER_NONNULL = YES; 262 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 263 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 264 | CLANG_CXX_LIBRARY = "libc++"; 265 | CLANG_ENABLE_MODULES = YES; 266 | CLANG_ENABLE_OBJC_ARC = YES; 267 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 268 | CLANG_WARN_BOOL_CONVERSION = YES; 269 | CLANG_WARN_COMMA = YES; 270 | CLANG_WARN_CONSTANT_CONVERSION = YES; 271 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 272 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 273 | CLANG_WARN_EMPTY_BODY = YES; 274 | CLANG_WARN_ENUM_CONVERSION = YES; 275 | CLANG_WARN_INFINITE_RECURSION = YES; 276 | CLANG_WARN_INT_CONVERSION = YES; 277 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 278 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 279 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 280 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 281 | CLANG_WARN_STRICT_PROTOTYPES = YES; 282 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 283 | CLANG_WARN_UNREACHABLE_CODE = YES; 284 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 285 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 286 | COPY_PHASE_STRIP = NO; 287 | DEBUG_INFORMATION_FORMAT = dwarf; 288 | ENABLE_STRICT_OBJC_MSGSEND = YES; 289 | ENABLE_TESTABILITY = YES; 290 | GCC_C_LANGUAGE_STANDARD = gnu99; 291 | GCC_DYNAMIC_NO_PIC = NO; 292 | GCC_NO_COMMON_BLOCKS = YES; 293 | GCC_OPTIMIZATION_LEVEL = 0; 294 | GCC_PREPROCESSOR_DEFINITIONS = ( 295 | "DEBUG=1", 296 | "$(inherited)", 297 | ); 298 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 299 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 300 | GCC_WARN_UNDECLARED_SELECTOR = YES; 301 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 302 | GCC_WARN_UNUSED_FUNCTION = YES; 303 | GCC_WARN_UNUSED_VARIABLE = YES; 304 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 305 | MTL_ENABLE_DEBUG_INFO = YES; 306 | ONLY_ACTIVE_ARCH = YES; 307 | SDKROOT = iphoneos; 308 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 309 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 310 | TARGETED_DEVICE_FAMILY = "1,2"; 311 | }; 312 | name = Debug; 313 | }; 314 | B07CD5891E90F27100677A5F /* Release */ = { 315 | isa = XCBuildConfiguration; 316 | buildSettings = { 317 | ALWAYS_SEARCH_USER_PATHS = NO; 318 | CLANG_ANALYZER_NONNULL = YES; 319 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 320 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 321 | CLANG_CXX_LIBRARY = "libc++"; 322 | CLANG_ENABLE_MODULES = YES; 323 | CLANG_ENABLE_OBJC_ARC = YES; 324 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 325 | CLANG_WARN_BOOL_CONVERSION = YES; 326 | CLANG_WARN_COMMA = YES; 327 | CLANG_WARN_CONSTANT_CONVERSION = YES; 328 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 329 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 330 | CLANG_WARN_EMPTY_BODY = YES; 331 | CLANG_WARN_ENUM_CONVERSION = YES; 332 | CLANG_WARN_INFINITE_RECURSION = YES; 333 | CLANG_WARN_INT_CONVERSION = YES; 334 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 335 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 336 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 337 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 338 | CLANG_WARN_STRICT_PROTOTYPES = YES; 339 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 340 | CLANG_WARN_UNREACHABLE_CODE = YES; 341 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 342 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 343 | COPY_PHASE_STRIP = NO; 344 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 345 | ENABLE_NS_ASSERTIONS = NO; 346 | ENABLE_STRICT_OBJC_MSGSEND = YES; 347 | GCC_C_LANGUAGE_STANDARD = gnu99; 348 | GCC_NO_COMMON_BLOCKS = YES; 349 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 350 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 351 | GCC_WARN_UNDECLARED_SELECTOR = YES; 352 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 353 | GCC_WARN_UNUSED_FUNCTION = YES; 354 | GCC_WARN_UNUSED_VARIABLE = YES; 355 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 356 | MTL_ENABLE_DEBUG_INFO = NO; 357 | SDKROOT = iphoneos; 358 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 359 | TARGETED_DEVICE_FAMILY = "1,2"; 360 | VALIDATE_PRODUCT = YES; 361 | }; 362 | name = Release; 363 | }; 364 | B07CD58B1E90F27100677A5F /* Debug */ = { 365 | isa = XCBuildConfiguration; 366 | baseConfigurationReference = EB883BD39A38AD64FC8C661E /* Pods-PinCodeView.debug.xcconfig */; 367 | buildSettings = { 368 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 369 | DEVELOPMENT_TEAM = F92RQULD22; 370 | INFOPLIST_FILE = PinCodeView/Info.plist; 371 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 372 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 373 | PRODUCT_BUNDLE_IDENTIFIER = com.dapulse.PinCodeViewDemo; 374 | PRODUCT_NAME = "$(TARGET_NAME)"; 375 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 376 | SWIFT_VERSION = 4.0; 377 | }; 378 | name = Debug; 379 | }; 380 | B07CD58C1E90F27100677A5F /* Release */ = { 381 | isa = XCBuildConfiguration; 382 | baseConfigurationReference = 2D68B860216C714BB51FBFBF /* Pods-PinCodeView.release.xcconfig */; 383 | buildSettings = { 384 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 385 | DEVELOPMENT_TEAM = F92RQULD22; 386 | INFOPLIST_FILE = PinCodeView/Info.plist; 387 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 388 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 389 | PRODUCT_BUNDLE_IDENTIFIER = com.dapulse.PinCodeViewDemo; 390 | PRODUCT_NAME = "$(TARGET_NAME)"; 391 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 392 | SWIFT_VERSION = 4.0; 393 | }; 394 | name = Release; 395 | }; 396 | /* End XCBuildConfiguration section */ 397 | 398 | /* Begin XCConfigurationList section */ 399 | B07CD5731E90F27100677A5F /* Build configuration list for PBXProject "PinCodeView" */ = { 400 | isa = XCConfigurationList; 401 | buildConfigurations = ( 402 | B07CD5881E90F27100677A5F /* Debug */, 403 | B07CD5891E90F27100677A5F /* Release */, 404 | ); 405 | defaultConfigurationIsVisible = 0; 406 | defaultConfigurationName = Release; 407 | }; 408 | B07CD58A1E90F27100677A5F /* Build configuration list for PBXNativeTarget "PinCodeViewDemo" */ = { 409 | isa = XCConfigurationList; 410 | buildConfigurations = ( 411 | B07CD58B1E90F27100677A5F /* Debug */, 412 | B07CD58C1E90F27100677A5F /* Release */, 413 | ); 414 | defaultConfigurationIsVisible = 0; 415 | defaultConfigurationName = Release; 416 | }; 417 | /* End XCConfigurationList section */ 418 | }; 419 | rootObject = B07CD5701E90F27100677A5F /* Project object */; 420 | } 421 | -------------------------------------------------------------------------------- /PinCodeViewDemo/PinCodeView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /PinCodeViewDemo/PinCodeView.xcodeproj/xcuserdata/ariel.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /PinCodeViewDemo/PinCodeView.xcodeproj/xcuserdata/ariel.xcuserdatad/xcschemes/PinCodeView.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 33 | 34 | 40 | 41 | 42 | 43 | 44 | 45 | 56 | 58 | 64 | 65 | 66 | 67 | 68 | 69 | 75 | 77 | 83 | 84 | 85 | 86 | 88 | 89 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /PinCodeViewDemo/PinCodeView.xcodeproj/xcuserdata/ariel.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | PinCodeView.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | B07CD5771E90F27100677A5F 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /PinCodeViewDemo/PinCodeView.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /PinCodeViewDemo/PinCodeView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // PinCodeView 4 | // 5 | // Created by Ariel Pollack on 02/04/2017. 6 | // Copyright © 2017 Dapulse. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /PinCodeViewDemo/PinCodeView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /PinCodeViewDemo/PinCodeView/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /PinCodeViewDemo/PinCodeView/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 37 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /PinCodeViewDemo/PinCodeView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /PinCodeViewDemo/PinCodeView/PinCodeDigitSquareView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PinCodeDigitSquareView.swift 3 | // PinCodeView 4 | // 5 | // Created by Ariel Pollack on 02/04/2017. 6 | // Copyright © 2017 Dapulse. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import PinCodeView 11 | 12 | public class PinCodeDigitSquareView: UILabel, PinCodeDigitView { 13 | 14 | public var state: PinCodeDigitViewState! = .empty { 15 | didSet { 16 | if state != oldValue { 17 | configure(withState: state) 18 | } 19 | } 20 | } 21 | 22 | public var digit: String? { 23 | didSet { 24 | guard digit != oldValue else { return } 25 | self.state = digit != nil ? .hasDigit : .empty 26 | self.text = digit 27 | } 28 | } 29 | 30 | convenience required public init() { 31 | self.init(frame: .zero) 32 | 33 | self.textAlignment = .center 34 | self.font = UIFont.systemFont(ofSize: 30) 35 | self.layer.borderWidth = 2 36 | self.layer.cornerRadius = 3 37 | self.textColor = UIColor(red: 51.0/255.0, green: 51.0/255.0, blue: 51.0/255.0, alpha: 1) 38 | self.configure(withState: .empty) 39 | 40 | translatesAutoresizingMaskIntoConstraints = false 41 | widthAnchor.constraint(equalToConstant: 40).isActive = true 42 | } 43 | 44 | public func configure(withState state: PinCodeDigitViewState) { 45 | switch state { 46 | case .empty: 47 | layer.borderColor = UIColor(red: 151.0/255.0, green: 151.0/255.0, blue: 151.0/255.0, alpha: 1).cgColor 48 | 49 | case .hasDigit: 50 | layer.borderColor = UIColor(red: 0, green: 161.0/255.0, blue: 230.0/255.0, alpha: 1).cgColor 51 | 52 | case .failedVerification: 53 | layer.borderColor = UIColor(red: 246.0/255.0, green: 95.0/255.0, blue: 124.0/255.0, alpha: 1).cgColor 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /PinCodeViewDemo/PinCodeView/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // PinCodeView 4 | // 5 | // Created by Ariel Pollack on 02/04/2017. 6 | // Copyright © 2017 Dapulse. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import PinCodeView 11 | import RxSwift 12 | import RxCocoa 13 | 14 | class ViewController: UIViewController { 15 | 16 | @IBOutlet weak var pinView: PinCodeView! { 17 | didSet { 18 | pinView.delegate = self 19 | pinView.numberOfDigits = 6 20 | pinView.groupingSize = 0 21 | pinView.itemSpacing = 7 22 | pinView.digitViewInit = PinCodeDigitSquareView.init 23 | } 24 | } 25 | } 26 | 27 | class RxViewController: ViewController { 28 | 29 | private let disposeBag = DisposeBag() 30 | 31 | override func viewDidLoad() { 32 | super.viewDidLoad() 33 | 34 | pinView.rx 35 | .didSubmit 36 | .subscribe(onNext: { [weak self] code in 37 | self?.submit(code: code) 38 | }) 39 | .disposed(by: disposeBag) 40 | } 41 | 42 | fileprivate func submit(code: String) { 43 | 44 | } 45 | } 46 | 47 | extension ViewController: PinCodeViewDelegate { 48 | func pinCodeView(_ view: PinCodeView, didInsertText text: String) { 49 | 50 | } 51 | 52 | func pinCodeView(_ view: PinCodeView, didSubmitPinCode code: String, isValidCallback callback: @escaping (Bool) -> Void) { 53 | 54 | view.alpha = 0.5 55 | 56 | // check server for code validity, etc 57 | DispatchQueue.main.asyncAfter(deadline: .now() + 2) { 58 | view.alpha = 1 59 | 60 | callback(false) 61 | } 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /PinCodeViewDemo/Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '9.0' 2 | 3 | target 'PinCodeView' do 4 | use_frameworks! 5 | 6 | pod 'PinCodeView/Core', :path => '../' 7 | pod 'PinCodeView/RxSwift', :path => '../' 8 | 9 | end 10 | -------------------------------------------------------------------------------- /PinCodeViewDemo/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - PinCodeView/Core (0.3.0) 3 | - PinCodeView/RxSwift (0.3.0): 4 | - PinCodeView/Core 5 | - RxCocoa 6 | - RxSwift 7 | - RxCocoa (4.1.2): 8 | - RxSwift (~> 4.0) 9 | - RxSwift (4.1.2) 10 | 11 | DEPENDENCIES: 12 | - PinCodeView/Core (from `../`) 13 | - PinCodeView/RxSwift (from `../`) 14 | 15 | EXTERNAL SOURCES: 16 | PinCodeView: 17 | :path: ../ 18 | 19 | SPEC CHECKSUMS: 20 | PinCodeView: d13dd98bb1f79d53f5f699d6422d1c7c2d1dae8c 21 | RxCocoa: d88ba0f1f6abf040011a9eb4b539324fc426843a 22 | RxSwift: e49536837d9901277638493ea537394d4b55f570 23 | 24 | PODFILE CHECKSUM: 5699376e337991fe3270d26b1920e6fde00a83c0 25 | 26 | COCOAPODS: 1.4.0 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PinCodeView 2 | 3 | `PinCodeView` is a drop-in pin code input field for digits and alpha-numerics. 4 | 5 | ![PinCodeView](Demo/PinCodeView.gif) 6 | 7 | ## Demo 8 | 9 | See `PinCodeView` in action on [Appetize.io](https://appetize.io/app/wtu3jz6kcex9cf6jdu1mjmyzrm) 10 | 11 | ## Instalation 12 | 13 | ### CocoaPods 14 | 15 | [CocoaPods](http://cocoapods.org) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like `PinCodeView` in your projects. 16 | 17 | First, add the following line to your [Podfile](http://guides.cocoapods.org/using/using-cocoapods.html): 18 | 19 | ```ruby 20 | pod 'PinCodeView' 21 | ``` 22 | 23 | Then, run the following line for integrating it into your project. 24 | 25 | ```ruby 26 | pod install 27 | ``` 28 | 29 | ### Manually 30 | 31 | Clone the repo, and drag the files inside `Source/` directory into your project 32 | 33 | ## Usage 34 | 35 | You can use `PinCodeView` from your interface builder or you can add it in code. 36 | 37 | In every case, you must provide some data for the view to know how to present. 38 | 39 | ### Add the view itself 40 | 41 | ```swift 42 | let pinView = PinCodeView(numberOfDigits: 6, textType: .numbers, groupingSize: 3, itemSpacing: 7) 43 | pinView.delegate = self 44 | pinView.digitViewInit = PinCodeDigitSquareView.init 45 | self.view.addSubview(pinView) 46 | // set your frame / constraints as you wish 47 | ``` 48 | 49 | ### Implement the delegate methods (optional) 50 | 51 | ```swift 52 | func pinCodeView(_ view: PinCodeView, didSubmitPinCode code: String, isValidCallback callback: @escaping (Bool) -> Void) { 53 | 54 | // here you can show your progress or do any UI action 55 | 56 | API.verifyCode(code, completion: { isValid in 57 | callback(isValid) 58 | }) 59 | } 60 | 61 | func pinCodeView(_ view: PinCodeView, didInsertText text: String) { 62 | // that's the place for hiding error views, etc 63 | } 64 | ``` 65 | 66 | ### Customizing! 67 | 68 | The view is implemented to allow customization for the single digit views. 69 | 70 | So, all you have to to is implement your own view that conform to `PinCodeDigitView`: 71 | 72 | ```swift 73 | public protocol PinCodeDigitView: class { 74 | init() 75 | var digit: String? { get set } 76 | var state: PinCodeDigitViewState! { get set } 77 | func configure(withState: PinCodeDigitViewState) 78 | 79 | // hackish way to constraint to UIView only 80 | var view: UIView { get } 81 | } 82 | ``` 83 | 84 | (note: if you have a better way to make it require the class to be UIView subclass create a pull request plz) 85 | 86 | ## License 87 | 88 | `PinCodeView` is distributed under the terms and conditions of the [MIT license](LICENSE.md). 89 | 90 | ## Credits 91 | 92 | `PinCodeView` is brought to you by Ariel Pollack, and was developed for [Dapulse](https://dapulse.com)'s iOS app. 93 | 94 | If you're using `PinCodeView` in your project, attribution would be very appreciated. -------------------------------------------------------------------------------- /Source/PinCodeView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Source/PinCodeView/PinCodeDigitView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PinCodeDigitView.swift 3 | // PinCodeView 4 | // 5 | // Created by Ariel Pollack on 03/04/2017. 6 | // Copyright © 2017 Dapulse. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public protocol PinCodeDigitView: class { 12 | init() 13 | var digit: String? { get set } 14 | var state: PinCodeDigitViewState! { get set } 15 | func configure(withState: PinCodeDigitViewState) 16 | 17 | // hackish way to constraint to UIView only 18 | var view: UIView { get } 19 | } 20 | 21 | public extension PinCodeDigitView where Self: UIView { 22 | var view: UIView { 23 | return self 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/PinCodeView/PinCodeSeparatorView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PinCodeSeparatorView.swift 3 | // PinCodeView 4 | // 5 | // Created by Ariel Pollack on 02/04/2017. 6 | // Copyright © 2017 Dapulse. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class PinCodeSeparatorView: UILabel { 12 | 13 | init(text: String) { 14 | super.init(frame: .zero) 15 | self.text = text 16 | self.font = UIFont.systemFont(ofSize: 30) 17 | self.textAlignment = .center 18 | self.setContentHuggingPriority(UILayoutPriority.required, for: .horizontal) 19 | self.sizeToFit() 20 | } 21 | 22 | required init?(coder aDecoder: NSCoder) { 23 | fatalError("init(coder:) has not been implemented") 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/PinCodeView/PinCodeView.h: -------------------------------------------------------------------------------- 1 | // 2 | // PinCodeView.h 3 | // PinCodeView 4 | // 5 | // Created by Ariel Pollack on 02/04/2017. 6 | // Copyright © 2017 Dapulse. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for PinCodeView. 12 | FOUNDATION_EXPORT double PinCodeViewVersionNumber; 13 | 14 | //! Project version string for PinCodeView. 15 | FOUNDATION_EXPORT const unsigned char PinCodeViewVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Source/PinCodeView/PinCodeView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PinCodeView.swift 3 | // PinCodeView 4 | // 5 | // Created by Ariel Pollack on 02/04/2017. 6 | // Copyright © 2017 Dapulse. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public enum PinCodeDigitViewState { 12 | case empty 13 | case hasDigit 14 | case failedVerification 15 | } 16 | 17 | fileprivate func ==(lhs: PinCodeView.State, rhs: PinCodeView.State) -> Bool { 18 | switch (lhs, rhs) { 19 | case (.inserting(let index1), .inserting(let index2)): 20 | return index1 == index2 21 | 22 | case (.finished, .finished), 23 | (.loading, .loading), 24 | (.disabled, .disabled): 25 | return true 26 | 27 | default: 28 | return false 29 | } 30 | } 31 | 32 | @objc public class PinCodeView: UIStackView { 33 | 34 | public enum TextType { 35 | case numbers 36 | case numbersAndLetters 37 | } 38 | 39 | fileprivate enum State: Equatable { 40 | case inserting(Int) 41 | case loading 42 | case finished 43 | case disabled 44 | } 45 | 46 | @objc public weak var delegate: PinCodeViewDelegate? 47 | 48 | /// support numbers and alphanumeric 49 | public var textType: TextType = .numbers 50 | 51 | /// initializer for the single digit views 52 | public var digitViewInit: (() -> PinCodeDigitView)! 53 | 54 | /// pretty straightforward 55 | @objc public var numberOfDigits: Int = 6 56 | 57 | /// group size for separating digits 58 | /// for example: 59 | /// group size of 3 will give ___ - ___ 60 | @objc public var groupingSize: Int = 3 61 | 62 | /// space between items 63 | @objc public var itemSpacing: Int = 2 64 | 65 | private var previousDigitState: State? 66 | public var isEnabled: Bool { 67 | get { return digitState != .disabled } 68 | set { 69 | if newValue == isEnabled { return } 70 | 71 | if !newValue { 72 | previousDigitState = digitState 73 | digitState = .disabled 74 | } else if let previousState = previousDigitState { 75 | digitState = previousState 76 | } 77 | } 78 | } 79 | 80 | fileprivate var digitViews = [PinCodeDigitView]() 81 | fileprivate var digitState: State = .inserting(0) { 82 | didSet { 83 | if case .inserting(0) = digitState { 84 | clearText() 85 | } 86 | } 87 | } 88 | 89 | public init(numberOfDigits: Int = 6, textType: TextType = .numbers, groupingSize: Int = 3, itemSpacing: Int = 2) { 90 | super.init(frame: .zero) 91 | 92 | self.numberOfDigits = numberOfDigits 93 | self.textType = textType 94 | self.groupingSize = groupingSize 95 | self.itemSpacing = itemSpacing 96 | 97 | configure() 98 | } 99 | 100 | @objc override public init(frame: CGRect) { 101 | super.init(frame: frame) 102 | configure() 103 | } 104 | 105 | @objc required public init(coder: NSCoder) { 106 | super.init(coder: coder) 107 | configure() 108 | } 109 | 110 | private func configure() { 111 | self.axis = .horizontal 112 | self.distribution = .fill 113 | self.translatesAutoresizingMaskIntoConstraints = false 114 | 115 | configureGestures() 116 | } 117 | 118 | private func configureGestures() { 119 | let tap = UITapGestureRecognizer(target: self, action: #selector(didTap)) 120 | addGestureRecognizer(tap) 121 | 122 | let longPress = UILongPressGestureRecognizer(target: self, action: #selector(didLongPress)) 123 | longPress.minimumPressDuration = 0.25 124 | addGestureRecognizer(longPress) 125 | } 126 | 127 | private func configureDigitViews() { 128 | assert(digitViewInit != nil, "must provide a single digit view initializer") 129 | 130 | self.spacing = CGFloat(itemSpacing) 131 | 132 | self.arrangedSubviews.forEach { view in 133 | self.removeArrangedSubview(view) 134 | view.removeFromSuperview() 135 | } 136 | 137 | digitViews = [] 138 | 139 | for _ in 0.. 0 { 147 | // TODO: better custom separators 148 | for idx in stride(from: groupingSize, to: numberOfDigits, by: groupingSize).reversed() { 149 | let separator = PinCodeSeparatorView(text: "-") 150 | self.insertArrangedSubview(separator, at: idx) 151 | } 152 | } 153 | } 154 | 155 | private var didLayoutSubviews = false 156 | override public func layoutSubviews() { 157 | super.layoutSubviews() 158 | 159 | if !didLayoutSubviews { 160 | didLayoutSubviews = true 161 | configureDigitViews() 162 | } 163 | } 164 | 165 | @objc func didTap() { 166 | guard !self.isFirstResponder else { return } 167 | becomeFirstResponder() 168 | } 169 | 170 | @objc func didLongPress(gesture: UILongPressGestureRecognizer) { 171 | guard gesture.state == .began else { return } 172 | 173 | if !self.isFirstResponder { 174 | self.becomeFirstResponder() 175 | } 176 | 177 | UIMenuController.shared.setTargetRect(self.bounds, in: self) 178 | UIMenuController.shared.setMenuVisible(true, animated: true) 179 | } 180 | 181 | // MARK: handle text input 182 | fileprivate var text: String { 183 | return digitViews.reduce("", { text, digitView in 184 | return text + (digitView.digit ?? "") 185 | }) 186 | } 187 | 188 | public func resetDigits() { 189 | digitState = .inserting(0) 190 | } 191 | 192 | func clearText() { 193 | for digitView in digitViews { 194 | digitView.digit = nil 195 | } 196 | } 197 | 198 | fileprivate var canReceiveText: Bool { 199 | return [.loading, .disabled].contains(digitState) == false 200 | } 201 | 202 | func submitDigits() { 203 | digitState = .loading 204 | 205 | delegate?.pinCodeView(self, didSubmitPinCode: text, isValidCallback: { [weak self] (isValid) in 206 | // we don't care about valid, the delegate will do something 207 | guard !isValid, let zelf = self else { return } 208 | 209 | if zelf.digitState == .loading { 210 | zelf.digitState = .finished 211 | } else { 212 | zelf.previousDigitState = .finished 213 | } 214 | 215 | for digitView in zelf.digitViews { 216 | digitView.state = .failedVerification 217 | } 218 | 219 | zelf.animateFailure() 220 | }) 221 | } 222 | 223 | private func animateFailure() { 224 | let anim = CABasicAnimation(keyPath: "position") 225 | anim.fromValue = NSValue(cgPoint: CGPoint(x: center.x - 5, y: center.y)) 226 | anim.toValue = NSValue(cgPoint: CGPoint(x: center.x + 5, y: center.y)) 227 | anim.duration = 0.07 228 | anim.repeatCount = 2 229 | anim.autoreverses = true 230 | layer.add(anim, forKey: "position") 231 | } 232 | } 233 | 234 | extension PinCodeView { 235 | override public func paste(_ sender: Any?) { 236 | guard let string = UIPasteboard.general.string else { return } 237 | let text: String 238 | switch textType { 239 | case .numbers: 240 | text = string.components(separatedBy: CharacterSet.decimalDigits.inverted).joined() 241 | 242 | case .numbersAndLetters: 243 | text = string.components(separatedBy: CharacterSet.alphanumerics.inverted).joined() 244 | } 245 | 246 | let index = text.index(text.startIndex, offsetBy: min(numberOfDigits, text.count)) 247 | insertText(String(text[.. Bool { 255 | return canReceiveText && action == #selector(paste(_:)) 256 | } 257 | 258 | public var keyboardType: UIKeyboardType { 259 | get { 260 | switch textType { 261 | case .numbers: 262 | return .numberPad 263 | 264 | case .numbersAndLetters: 265 | return .default 266 | } 267 | } 268 | set { 269 | // ignore manual user set 270 | } 271 | } 272 | } 273 | 274 | extension PinCodeView: UIKeyInput { 275 | public var hasText: Bool { 276 | return !text.isEmpty 277 | } 278 | 279 | private func isValidText(_ text: String) -> Bool { 280 | guard !text.isEmpty else { 281 | return false 282 | } 283 | 284 | let validCharacterSet: CharacterSet 285 | switch textType { 286 | case .numbers: 287 | validCharacterSet = .decimalDigits 288 | 289 | case .numbersAndLetters: 290 | validCharacterSet = .alphanumerics 291 | } 292 | 293 | guard let scalar = UnicodeScalar(text), 294 | validCharacterSet.contains(scalar) else { 295 | return false 296 | } 297 | 298 | return true 299 | } 300 | 301 | public func insertText(_ text: String) { 302 | guard canReceiveText else { return } 303 | 304 | // if inserting more than 1 character, reset all values and put new text 305 | guard text.count == 1 else { 306 | digitState = .inserting(0) 307 | text.map({ "\($0)" }).forEach(insertText) 308 | return 309 | } 310 | 311 | guard isValidText(text) else { return } 312 | 313 | delegate?.pinCodeView(self, didInsertText: text) 314 | 315 | // state machine 316 | switch digitState { 317 | case .inserting(let digitIndex): 318 | let digitView = digitViews[digitIndex] 319 | digitView.digit = text 320 | 321 | if digitIndex + 1 == numberOfDigits { 322 | digitState = .finished 323 | submitDigits() 324 | } else { 325 | digitState = .inserting(digitIndex + 1) 326 | } 327 | 328 | case .finished: 329 | digitState = .inserting(0) 330 | insertText(text) 331 | 332 | default: break 333 | } 334 | 335 | } 336 | 337 | public func deleteBackward() { 338 | guard canReceiveText else { return } 339 | 340 | delegate?.pinCodeView(self, didInsertText: "") 341 | 342 | switch digitState { 343 | case .inserting(let index) where index > 0: 344 | let digitView = digitViews[index - 1] 345 | digitView.digit = nil 346 | 347 | digitState = .inserting(index - 1) 348 | 349 | case .finished: 350 | digitState = .inserting(0) 351 | 352 | default: break 353 | } 354 | } 355 | } 356 | -------------------------------------------------------------------------------- /Source/PinCodeView/PinCodeViewDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PinCodeViewDelegate.swift 3 | // PinCodeView 4 | // 5 | // Created by Ariel Pollack on 02/04/2017. 6 | // Copyright © 2017 Dapulse. All rights reserved. 7 | // 8 | 9 | @objc public protocol PinCodeViewDelegate: class { 10 | func pinCodeView(_ view: PinCodeView, didSubmitPinCode code: String, isValidCallback callback: @escaping (Bool)->Void) 11 | func pinCodeView(_ view: PinCodeView, didInsertText text: String) 12 | } 13 | 14 | extension PinCodeViewDelegate { 15 | func pinCodeView(_ view: PinCodeView, didInsertText text: String) {} 16 | } 17 | -------------------------------------------------------------------------------- /Source/RxSwift/PinCodeView+Rx.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PinCodeView+Rx.swift 3 | // PinCodeView 4 | // 5 | // Created by Ariel Pollack on 29/06/2017. 6 | // Copyright © 2017 Dapulse. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import RxSwift 11 | import RxCocoa 12 | #if !COCOAPODS 13 | import PinCodeView 14 | #endif 15 | 16 | fileprivate class PinCodeViewDelegateProxy: PinCodeViewDelegate { 17 | 18 | weak var delegate: PinCodeViewDelegate? 19 | internal var didSubmit = PublishSubject() 20 | internal var submitCodeCallback: ((Bool)->Void)? 21 | 22 | init(pinCodeView view: PinCodeView) { 23 | self.delegate = view.delegate 24 | } 25 | 26 | func pinCodeView(_ view: PinCodeView, didSubmitPinCode code: String, isValidCallback callback: @escaping (Bool)->Void) { 27 | submitCodeCallback = callback 28 | didSubmit.onNext(code) 29 | self.delegate?.pinCodeView(view, didSubmitPinCode: code, isValidCallback: callback) 30 | } 31 | 32 | func pinCodeView(_ view: PinCodeView, didInsertText text: String) { 33 | self.delegate?.pinCodeView(view, didInsertText: text) 34 | } 35 | } 36 | 37 | extension Reactive where Base: PinCodeView { 38 | 39 | public var didSubmit: Observable { 40 | let delegateProxy = PinCodeViewDelegateProxy(pinCodeView: base) 41 | base.delegate = delegateProxy 42 | return delegateProxy.didSubmit.asObservable() 43 | } 44 | } 45 | --------------------------------------------------------------------------------