├── .DS_Store ├── .gitignore ├── LICENSE ├── README.md └── SwiftyVerificationCodeView ├── SwiftyVerificationCodeView.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── SwiftyVerificationCodeView ├── AppDelegate.swift ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── SwiftyTextField.swift ├── SwiftyVerificationCodeView.swift ├── VerificationCode.gif └── ViewController.swift /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KFCFans/SwiftyVerificationCodeView/afcb36ecd21eb41aa8c4089c05f3783a3d1ee9a6/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/Preview.html 64 | fastlane/screenshots 65 | fastlane/test_output 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 LoveAlwaysYoung 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SwiftyVerificationCodeView 2 | 仿滴滴短信验证码输入框 ,swift3实现 3 | 4 | ![image](https://github.com/LoveAlwaysYoung/SwiftyVerificationCodeView/blob/master/SwiftyVerificationCodeView/SwiftyVerificationCodeView/VerificationCode.gif) 5 | -------------------------------------------------------------------------------- /SwiftyVerificationCodeView/SwiftyVerificationCodeView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 366112691E969AE8005D0A96 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 366112681E969AE8005D0A96 /* AppDelegate.swift */; }; 11 | 3661126B1E969AE8005D0A96 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3661126A1E969AE8005D0A96 /* ViewController.swift */; }; 12 | 3661126E1E969AE8005D0A96 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3661126C1E969AE8005D0A96 /* Main.storyboard */; }; 13 | 366112701E969AE8005D0A96 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3661126F1E969AE8005D0A96 /* Assets.xcassets */; }; 14 | 366112731E969AE8005D0A96 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 366112711E969AE8005D0A96 /* LaunchScreen.storyboard */; }; 15 | 3661127C1E969B00005D0A96 /* SwiftyTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3661127A1E969B00005D0A96 /* SwiftyTextField.swift */; }; 16 | 3661127D1E969B00005D0A96 /* SwiftyVerificationCodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3661127B1E969B00005D0A96 /* SwiftyVerificationCodeView.swift */; }; 17 | 3664E1E81E9733F90041259B /* VerificationCode.gif in Resources */ = {isa = PBXBuildFile; fileRef = 3664E1E71E9733F90041259B /* VerificationCode.gif */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 366112651E969AE8005D0A96 /* SwiftyVerificationCodeView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftyVerificationCodeView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 366112681E969AE8005D0A96 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | 3661126A1E969AE8005D0A96 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | 3661126D1E969AE8005D0A96 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | 3661126F1E969AE8005D0A96 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | 366112721E969AE8005D0A96 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | 366112741E969AE8005D0A96 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | 3661127A1E969B00005D0A96 /* SwiftyTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyTextField.swift; sourceTree = ""; }; 29 | 3661127B1E969B00005D0A96 /* SwiftyVerificationCodeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyVerificationCodeView.swift; sourceTree = ""; }; 30 | 3664E1E71E9733F90041259B /* VerificationCode.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = VerificationCode.gif; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | 366112621E969AE8005D0A96 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | 3661125C1E969AE7005D0A96 = { 45 | isa = PBXGroup; 46 | children = ( 47 | 366112671E969AE8005D0A96 /* SwiftyVerificationCodeView */, 48 | 366112661E969AE8005D0A96 /* Products */, 49 | ); 50 | sourceTree = ""; 51 | }; 52 | 366112661E969AE8005D0A96 /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | 366112651E969AE8005D0A96 /* SwiftyVerificationCodeView.app */, 56 | ); 57 | name = Products; 58 | sourceTree = ""; 59 | }; 60 | 366112671E969AE8005D0A96 /* SwiftyVerificationCodeView */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 3661127A1E969B00005D0A96 /* SwiftyTextField.swift */, 64 | 3661127B1E969B00005D0A96 /* SwiftyVerificationCodeView.swift */, 65 | 366112681E969AE8005D0A96 /* AppDelegate.swift */, 66 | 3661126A1E969AE8005D0A96 /* ViewController.swift */, 67 | 3661126C1E969AE8005D0A96 /* Main.storyboard */, 68 | 3661126F1E969AE8005D0A96 /* Assets.xcassets */, 69 | 366112711E969AE8005D0A96 /* LaunchScreen.storyboard */, 70 | 366112741E969AE8005D0A96 /* Info.plist */, 71 | 3664E1E71E9733F90041259B /* VerificationCode.gif */, 72 | ); 73 | path = SwiftyVerificationCodeView; 74 | sourceTree = ""; 75 | }; 76 | /* End PBXGroup section */ 77 | 78 | /* Begin PBXNativeTarget section */ 79 | 366112641E969AE8005D0A96 /* SwiftyVerificationCodeView */ = { 80 | isa = PBXNativeTarget; 81 | buildConfigurationList = 366112771E969AE8005D0A96 /* Build configuration list for PBXNativeTarget "SwiftyVerificationCodeView" */; 82 | buildPhases = ( 83 | 366112611E969AE8005D0A96 /* Sources */, 84 | 366112621E969AE8005D0A96 /* Frameworks */, 85 | 366112631E969AE8005D0A96 /* Resources */, 86 | ); 87 | buildRules = ( 88 | ); 89 | dependencies = ( 90 | ); 91 | name = SwiftyVerificationCodeView; 92 | productName = SwiftyVerificationCodeView; 93 | productReference = 366112651E969AE8005D0A96 /* SwiftyVerificationCodeView.app */; 94 | productType = "com.apple.product-type.application"; 95 | }; 96 | /* End PBXNativeTarget section */ 97 | 98 | /* Begin PBXProject section */ 99 | 3661125D1E969AE7005D0A96 /* Project object */ = { 100 | isa = PBXProject; 101 | attributes = { 102 | LastSwiftUpdateCheck = 0820; 103 | LastUpgradeCheck = 0820; 104 | ORGANIZATIONNAME = lip; 105 | TargetAttributes = { 106 | 366112641E969AE8005D0A96 = { 107 | CreatedOnToolsVersion = 8.2.1; 108 | DevelopmentTeam = HR6CZ7SBBE; 109 | ProvisioningStyle = Automatic; 110 | }; 111 | }; 112 | }; 113 | buildConfigurationList = 366112601E969AE7005D0A96 /* Build configuration list for PBXProject "SwiftyVerificationCodeView" */; 114 | compatibilityVersion = "Xcode 3.2"; 115 | developmentRegion = English; 116 | hasScannedForEncodings = 0; 117 | knownRegions = ( 118 | en, 119 | Base, 120 | ); 121 | mainGroup = 3661125C1E969AE7005D0A96; 122 | productRefGroup = 366112661E969AE8005D0A96 /* Products */; 123 | projectDirPath = ""; 124 | projectRoot = ""; 125 | targets = ( 126 | 366112641E969AE8005D0A96 /* SwiftyVerificationCodeView */, 127 | ); 128 | }; 129 | /* End PBXProject section */ 130 | 131 | /* Begin PBXResourcesBuildPhase section */ 132 | 366112631E969AE8005D0A96 /* Resources */ = { 133 | isa = PBXResourcesBuildPhase; 134 | buildActionMask = 2147483647; 135 | files = ( 136 | 366112731E969AE8005D0A96 /* LaunchScreen.storyboard in Resources */, 137 | 366112701E969AE8005D0A96 /* Assets.xcassets in Resources */, 138 | 3664E1E81E9733F90041259B /* VerificationCode.gif in Resources */, 139 | 3661126E1E969AE8005D0A96 /* Main.storyboard in Resources */, 140 | ); 141 | runOnlyForDeploymentPostprocessing = 0; 142 | }; 143 | /* End PBXResourcesBuildPhase section */ 144 | 145 | /* Begin PBXSourcesBuildPhase section */ 146 | 366112611E969AE8005D0A96 /* Sources */ = { 147 | isa = PBXSourcesBuildPhase; 148 | buildActionMask = 2147483647; 149 | files = ( 150 | 3661127D1E969B00005D0A96 /* SwiftyVerificationCodeView.swift in Sources */, 151 | 3661127C1E969B00005D0A96 /* SwiftyTextField.swift in Sources */, 152 | 3661126B1E969AE8005D0A96 /* ViewController.swift in Sources */, 153 | 366112691E969AE8005D0A96 /* AppDelegate.swift in Sources */, 154 | ); 155 | runOnlyForDeploymentPostprocessing = 0; 156 | }; 157 | /* End PBXSourcesBuildPhase section */ 158 | 159 | /* Begin PBXVariantGroup section */ 160 | 3661126C1E969AE8005D0A96 /* Main.storyboard */ = { 161 | isa = PBXVariantGroup; 162 | children = ( 163 | 3661126D1E969AE8005D0A96 /* Base */, 164 | ); 165 | name = Main.storyboard; 166 | sourceTree = ""; 167 | }; 168 | 366112711E969AE8005D0A96 /* LaunchScreen.storyboard */ = { 169 | isa = PBXVariantGroup; 170 | children = ( 171 | 366112721E969AE8005D0A96 /* Base */, 172 | ); 173 | name = LaunchScreen.storyboard; 174 | sourceTree = ""; 175 | }; 176 | /* End PBXVariantGroup section */ 177 | 178 | /* Begin XCBuildConfiguration section */ 179 | 366112751E969AE8005D0A96 /* Debug */ = { 180 | isa = XCBuildConfiguration; 181 | buildSettings = { 182 | ALWAYS_SEARCH_USER_PATHS = NO; 183 | CLANG_ANALYZER_NONNULL = YES; 184 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 185 | CLANG_CXX_LIBRARY = "libc++"; 186 | CLANG_ENABLE_MODULES = YES; 187 | CLANG_ENABLE_OBJC_ARC = YES; 188 | CLANG_WARN_BOOL_CONVERSION = YES; 189 | CLANG_WARN_CONSTANT_CONVERSION = YES; 190 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 191 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 192 | CLANG_WARN_EMPTY_BODY = YES; 193 | CLANG_WARN_ENUM_CONVERSION = YES; 194 | CLANG_WARN_INFINITE_RECURSION = YES; 195 | CLANG_WARN_INT_CONVERSION = YES; 196 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 197 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 198 | CLANG_WARN_UNREACHABLE_CODE = YES; 199 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 200 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 201 | COPY_PHASE_STRIP = NO; 202 | DEBUG_INFORMATION_FORMAT = dwarf; 203 | ENABLE_STRICT_OBJC_MSGSEND = YES; 204 | ENABLE_TESTABILITY = YES; 205 | GCC_C_LANGUAGE_STANDARD = gnu99; 206 | GCC_DYNAMIC_NO_PIC = NO; 207 | GCC_NO_COMMON_BLOCKS = YES; 208 | GCC_OPTIMIZATION_LEVEL = 0; 209 | GCC_PREPROCESSOR_DEFINITIONS = ( 210 | "DEBUG=1", 211 | "$(inherited)", 212 | ); 213 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 214 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 215 | GCC_WARN_UNDECLARED_SELECTOR = YES; 216 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 217 | GCC_WARN_UNUSED_FUNCTION = YES; 218 | GCC_WARN_UNUSED_VARIABLE = YES; 219 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 220 | MTL_ENABLE_DEBUG_INFO = YES; 221 | ONLY_ACTIVE_ARCH = YES; 222 | SDKROOT = iphoneos; 223 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 224 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 225 | }; 226 | name = Debug; 227 | }; 228 | 366112761E969AE8005D0A96 /* Release */ = { 229 | isa = XCBuildConfiguration; 230 | buildSettings = { 231 | ALWAYS_SEARCH_USER_PATHS = NO; 232 | CLANG_ANALYZER_NONNULL = YES; 233 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 234 | CLANG_CXX_LIBRARY = "libc++"; 235 | CLANG_ENABLE_MODULES = YES; 236 | CLANG_ENABLE_OBJC_ARC = YES; 237 | CLANG_WARN_BOOL_CONVERSION = YES; 238 | CLANG_WARN_CONSTANT_CONVERSION = YES; 239 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 240 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 241 | CLANG_WARN_EMPTY_BODY = YES; 242 | CLANG_WARN_ENUM_CONVERSION = YES; 243 | CLANG_WARN_INFINITE_RECURSION = YES; 244 | CLANG_WARN_INT_CONVERSION = YES; 245 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 246 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 247 | CLANG_WARN_UNREACHABLE_CODE = YES; 248 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 249 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 250 | COPY_PHASE_STRIP = NO; 251 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 252 | ENABLE_NS_ASSERTIONS = NO; 253 | ENABLE_STRICT_OBJC_MSGSEND = YES; 254 | GCC_C_LANGUAGE_STANDARD = gnu99; 255 | GCC_NO_COMMON_BLOCKS = YES; 256 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 257 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 258 | GCC_WARN_UNDECLARED_SELECTOR = YES; 259 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 260 | GCC_WARN_UNUSED_FUNCTION = YES; 261 | GCC_WARN_UNUSED_VARIABLE = YES; 262 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 263 | MTL_ENABLE_DEBUG_INFO = NO; 264 | SDKROOT = iphoneos; 265 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 266 | VALIDATE_PRODUCT = YES; 267 | }; 268 | name = Release; 269 | }; 270 | 366112781E969AE8005D0A96 /* Debug */ = { 271 | isa = XCBuildConfiguration; 272 | buildSettings = { 273 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 274 | DEVELOPMENT_TEAM = HR6CZ7SBBE; 275 | INFOPLIST_FILE = SwiftyVerificationCodeView/Info.plist; 276 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 277 | PRODUCT_BUNDLE_IDENTIFIER = com.lip.SwiftyVerificationCodeView; 278 | PRODUCT_NAME = "$(TARGET_NAME)"; 279 | SWIFT_VERSION = 3.0; 280 | }; 281 | name = Debug; 282 | }; 283 | 366112791E969AE8005D0A96 /* Release */ = { 284 | isa = XCBuildConfiguration; 285 | buildSettings = { 286 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 287 | DEVELOPMENT_TEAM = HR6CZ7SBBE; 288 | INFOPLIST_FILE = SwiftyVerificationCodeView/Info.plist; 289 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 290 | PRODUCT_BUNDLE_IDENTIFIER = com.lip.SwiftyVerificationCodeView; 291 | PRODUCT_NAME = "$(TARGET_NAME)"; 292 | SWIFT_VERSION = 3.0; 293 | }; 294 | name = Release; 295 | }; 296 | /* End XCBuildConfiguration section */ 297 | 298 | /* Begin XCConfigurationList section */ 299 | 366112601E969AE7005D0A96 /* Build configuration list for PBXProject "SwiftyVerificationCodeView" */ = { 300 | isa = XCConfigurationList; 301 | buildConfigurations = ( 302 | 366112751E969AE8005D0A96 /* Debug */, 303 | 366112761E969AE8005D0A96 /* Release */, 304 | ); 305 | defaultConfigurationIsVisible = 0; 306 | defaultConfigurationName = Release; 307 | }; 308 | 366112771E969AE8005D0A96 /* Build configuration list for PBXNativeTarget "SwiftyVerificationCodeView" */ = { 309 | isa = XCConfigurationList; 310 | buildConfigurations = ( 311 | 366112781E969AE8005D0A96 /* Debug */, 312 | 366112791E969AE8005D0A96 /* Release */, 313 | ); 314 | defaultConfigurationIsVisible = 0; 315 | defaultConfigurationName = Release; 316 | }; 317 | /* End XCConfigurationList section */ 318 | }; 319 | rootObject = 3661125D1E969AE7005D0A96 /* Project object */; 320 | } 321 | -------------------------------------------------------------------------------- /SwiftyVerificationCodeView/SwiftyVerificationCodeView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SwiftyVerificationCodeView/SwiftyVerificationCodeView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SwiftyVerificationCodeView 4 | // 5 | // Created by lip on 17/4/6. 6 | // Copyright © 2017年 lip. 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 | window = UIWindow() 19 | window?.rootViewController = ViewController() 20 | window?.makeKeyAndVisible() 21 | return true 22 | } 23 | 24 | func applicationWillResignActive(_ application: UIApplication) { 25 | // 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. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | func applicationDidEnterBackground(_ application: UIApplication) { 30 | // 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. 31 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 32 | } 33 | 34 | func applicationWillEnterForeground(_ application: UIApplication) { 35 | // 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. 36 | } 37 | 38 | func applicationDidBecomeActive(_ application: UIApplication) { 39 | // 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. 40 | } 41 | 42 | func applicationWillTerminate(_ application: UIApplication) { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | 47 | } 48 | 49 | -------------------------------------------------------------------------------- /SwiftyVerificationCodeView/SwiftyVerificationCodeView/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 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /SwiftyVerificationCodeView/SwiftyVerificationCodeView/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 | -------------------------------------------------------------------------------- /SwiftyVerificationCodeView/SwiftyVerificationCodeView/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 | -------------------------------------------------------------------------------- /SwiftyVerificationCodeView/SwiftyVerificationCodeView/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 | 38 | 39 | -------------------------------------------------------------------------------- /SwiftyVerificationCodeView/SwiftyVerificationCodeView/SwiftyTextField.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TestTextField.swift 3 | // EULoginTemp 4 | // 5 | // Created by lip on 17/4/6. 6 | // Copyright © 2017年 lip. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | 12 | protocol SwiftyTextFieldDeleteDelegate { 13 | func didClickBackWard() 14 | } 15 | 16 | class SwiftyTextField: UITextField { 17 | 18 | var deleteDelegate:SwiftyTextFieldDeleteDelegate? 19 | 20 | override func deleteBackward() { 21 | super.deleteBackward() 22 | deleteDelegate?.didClickBackWard() 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /SwiftyVerificationCodeView/SwiftyVerificationCodeView/SwiftyVerificationCodeView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftyVerificationCodeView.swift 3 | // EULoginTemp 4 | // 5 | // Created by lip on 17/4/6. 6 | // Copyright © 2017年 lip. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | /** 11 | 滴滴验证码的逻辑 12 | 不允许用户点击,顺序已经定死,可以用删除键回退,最后一个输完自动登陆 13 | */ 14 | 15 | protocol SwiftyVerificationCodeViewDelegate { 16 | func verificationCodeDidFinishedInput(verificationCodeView:SwiftyVerificationCodeView,code:String) 17 | } 18 | class SwiftyVerificationCodeView: UIView { 19 | 20 | /// 代理回调 21 | var delegate:SwiftyVerificationCodeViewDelegate? 22 | 23 | /// 一堆框框的数组 24 | var textfieldarray = [UITextField]() 25 | 26 | /// 框框之间的间隔 27 | let margin:CGFloat = 10 28 | 29 | /// 框框的大小 30 | let width:CGFloat = 50 31 | 32 | /// 框框个数 33 | var numOfRect = 4 34 | 35 | /// 构造函数 36 | /// 37 | /// - Parameters: 38 | /// - frame: frame,宽度最好设置为屏幕宽度 39 | /// - num: 框框个数,默认 4 个 40 | /// - margin: 框框之间的间距,默认 10 41 | init(frame: CGRect,num:Int = 4,margin:CGFloat = 10) { 42 | super.init(frame: frame) 43 | setupUI() 44 | } 45 | 46 | 47 | required init?(coder aDecoder: NSCoder) { 48 | fatalError("init(coder:) has not been implemented") 49 | } 50 | 51 | func cleanVerificationCodeView(){ 52 | 53 | for tv in textfieldarray { 54 | tv.text = "" 55 | } 56 | textfieldarray.first?.becomeFirstResponder() 57 | 58 | 59 | } 60 | 61 | } 62 | 63 | // MARK: - UI 相关方法 64 | extension SwiftyVerificationCodeView{ 65 | 66 | fileprivate func setupUI(){ 67 | 68 | // 不允许用户直接操作验证码框 69 | self.isUserInteractionEnabled = false 70 | 71 | // 计算左间距 72 | let leftmargin = (UIScreen.main.bounds.width - width * CGFloat(numOfRect) - CGFloat(numOfRect - 1) * margin) / 2 73 | 74 | // 创建 n个 UITextFiedl 75 | for i in 0..UITextField{ 94 | 95 | let tv = SwiftyTextField(frame: frame) 96 | tv.borderStyle = .line 97 | tv.textAlignment = .center 98 | tv.font = UIFont.boldSystemFont(ofSize: 40) 99 | tv.textColor = UIColor.init(red: 51/255, green: 51/255, blue: 51/255, alpha: 1) 100 | tv.delegate = self 101 | tv.deleteDelegate = self 102 | addSubview(tv) 103 | tv.keyboardType = .numberPad 104 | return tv 105 | 106 | } 107 | 108 | } 109 | 110 | 111 | 112 | extension SwiftyVerificationCodeView:UITextFieldDelegate,SwiftyTextFieldDeleteDelegate{ 113 | 114 | func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { 115 | 116 | if !textField.hasText { 117 | 118 | // tag 对应数组下标 119 | let index = textField.tag 120 | 121 | textField.resignFirstResponder() 122 | if index == numOfRect - 1 { 123 | textfieldarray[index].text = string 124 | // 拼接结果 125 | var code = "" 126 | for tv in textfieldarray{ 127 | code += tv.text ?? "" 128 | } 129 | delegate?.verificationCodeDidFinishedInput(verificationCodeView: self, code: code) 130 | return false 131 | } 132 | 133 | textfieldarray[index].text = string 134 | textfieldarray[index + 1].becomeFirstResponder() 135 | 136 | } 137 | return false 138 | 139 | } 140 | 141 | /// 监听键盘删除键 142 | func didClickBackWard() { 143 | 144 | for i in 1..