├── .gitignore ├── Example └── HideShowPasswordTextFieldExample │ ├── HideShowPasswordTextFieldExample.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── HideShowPasswordTextFieldExample │ ├── AppDelegate.swift │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ └── ViewController.swift ├── HideShowPasswordTextField.podspec ├── HideShowPasswordTextField ├── HideShowPasswordTextField.swift ├── PasswordToggleVisibilityView.swift ├── ic_eye_closed.png ├── ic_eye_closed@2x.png ├── ic_eye_closed@3x.png ├── ic_eye_open.png ├── ic_eye_open@2x.png ├── ic_eye_open@3x.png ├── ic_password_checkmark.png ├── ic_password_checkmark@2x.png └── ic_password_checkmark@3x.png ├── LICENSE └── README.md /.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 | *.xccheckout 22 | *.moved-aside 23 | *.xcuserstate 24 | *.xcscmblueprint 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 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/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/screenshots 64 | -------------------------------------------------------------------------------- /Example/HideShowPasswordTextFieldExample/HideShowPasswordTextFieldExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 7C8BC4CD1CD7EB3700402247 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8BC4CC1CD7EB3700402247 /* AppDelegate.swift */; }; 11 | 7C8BC4CF1CD7EB3700402247 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8BC4CE1CD7EB3700402247 /* ViewController.swift */; }; 12 | 7C8BC4D21CD7EB3700402247 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7C8BC4D01CD7EB3700402247 /* Main.storyboard */; }; 13 | 7C8BC4D41CD7EB3700402247 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7C8BC4D31CD7EB3700402247 /* Assets.xcassets */; }; 14 | 7C8BC4D71CD7EB3700402247 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7C8BC4D51CD7EB3700402247 /* LaunchScreen.storyboard */; }; 15 | 7C8BC4E11CD7EB4700402247 /* HideShowPasswordTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8BC4DF1CD7EB4700402247 /* HideShowPasswordTextField.swift */; }; 16 | 7C8BC4E21CD7EB4700402247 /* PasswordToggleVisibilityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8BC4E01CD7EB4700402247 /* PasswordToggleVisibilityView.swift */; }; 17 | 7C8BC4EC1CD7ED9100402247 /* ic_eye_closed.png in Resources */ = {isa = PBXBuildFile; fileRef = 7C8BC4E31CD7ED9100402247 /* ic_eye_closed.png */; }; 18 | 7C8BC4ED1CD7ED9100402247 /* ic_eye_closed@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7C8BC4E41CD7ED9100402247 /* ic_eye_closed@2x.png */; }; 19 | 7C8BC4EE1CD7ED9100402247 /* ic_eye_closed@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7C8BC4E51CD7ED9100402247 /* ic_eye_closed@3x.png */; }; 20 | 7C8BC4EF1CD7ED9100402247 /* ic_eye_open.png in Resources */ = {isa = PBXBuildFile; fileRef = 7C8BC4E61CD7ED9100402247 /* ic_eye_open.png */; }; 21 | 7C8BC4F01CD7ED9100402247 /* ic_eye_open@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7C8BC4E71CD7ED9100402247 /* ic_eye_open@2x.png */; }; 22 | 7C8BC4F11CD7ED9100402247 /* ic_eye_open@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7C8BC4E81CD7ED9100402247 /* ic_eye_open@3x.png */; }; 23 | 7C8BC4F21CD7ED9100402247 /* ic_password_checkmark.png in Resources */ = {isa = PBXBuildFile; fileRef = 7C8BC4E91CD7ED9100402247 /* ic_password_checkmark.png */; }; 24 | 7C8BC4F31CD7ED9100402247 /* ic_password_checkmark@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7C8BC4EA1CD7ED9100402247 /* ic_password_checkmark@2x.png */; }; 25 | 7C8BC4F41CD7ED9100402247 /* ic_password_checkmark@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7C8BC4EB1CD7ED9100402247 /* ic_password_checkmark@3x.png */; }; 26 | /* End PBXBuildFile section */ 27 | 28 | /* Begin PBXFileReference section */ 29 | 7C8BC4C91CD7EB3700402247 /* HideShowPasswordTextFieldExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HideShowPasswordTextFieldExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | 7C8BC4CC1CD7EB3700402247 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 31 | 7C8BC4CE1CD7EB3700402247 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 32 | 7C8BC4D11CD7EB3700402247 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 33 | 7C8BC4D31CD7EB3700402247 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 34 | 7C8BC4D61CD7EB3700402247 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 35 | 7C8BC4D81CD7EB3700402247 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 36 | 7C8BC4DF1CD7EB4700402247 /* HideShowPasswordTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HideShowPasswordTextField.swift; sourceTree = ""; }; 37 | 7C8BC4E01CD7EB4700402247 /* PasswordToggleVisibilityView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordToggleVisibilityView.swift; sourceTree = ""; }; 38 | 7C8BC4E31CD7ED9100402247 /* ic_eye_closed.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ic_eye_closed.png; sourceTree = ""; }; 39 | 7C8BC4E41CD7ED9100402247 /* ic_eye_closed@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ic_eye_closed@2x.png"; sourceTree = ""; }; 40 | 7C8BC4E51CD7ED9100402247 /* ic_eye_closed@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ic_eye_closed@3x.png"; sourceTree = ""; }; 41 | 7C8BC4E61CD7ED9100402247 /* ic_eye_open.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ic_eye_open.png; sourceTree = ""; }; 42 | 7C8BC4E71CD7ED9100402247 /* ic_eye_open@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ic_eye_open@2x.png"; sourceTree = ""; }; 43 | 7C8BC4E81CD7ED9100402247 /* ic_eye_open@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ic_eye_open@3x.png"; sourceTree = ""; }; 44 | 7C8BC4E91CD7ED9100402247 /* ic_password_checkmark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ic_password_checkmark.png; sourceTree = ""; }; 45 | 7C8BC4EA1CD7ED9100402247 /* ic_password_checkmark@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ic_password_checkmark@2x.png"; sourceTree = ""; }; 46 | 7C8BC4EB1CD7ED9100402247 /* ic_password_checkmark@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ic_password_checkmark@3x.png"; sourceTree = ""; }; 47 | /* End PBXFileReference section */ 48 | 49 | /* Begin PBXFrameworksBuildPhase section */ 50 | 7C8BC4C61CD7EB3700402247 /* Frameworks */ = { 51 | isa = PBXFrameworksBuildPhase; 52 | buildActionMask = 2147483647; 53 | files = ( 54 | ); 55 | runOnlyForDeploymentPostprocessing = 0; 56 | }; 57 | /* End PBXFrameworksBuildPhase section */ 58 | 59 | /* Begin PBXGroup section */ 60 | 7C8BC4C01CD7EB3700402247 = { 61 | isa = PBXGroup; 62 | children = ( 63 | 7C8BC4DE1CD7EB4700402247 /* HideShowPasswordTextField */, 64 | 7C8BC4CB1CD7EB3700402247 /* HideShowPasswordTextFieldExample */, 65 | 7C8BC4CA1CD7EB3700402247 /* Products */, 66 | ); 67 | sourceTree = ""; 68 | }; 69 | 7C8BC4CA1CD7EB3700402247 /* Products */ = { 70 | isa = PBXGroup; 71 | children = ( 72 | 7C8BC4C91CD7EB3700402247 /* HideShowPasswordTextFieldExample.app */, 73 | ); 74 | name = Products; 75 | sourceTree = ""; 76 | }; 77 | 7C8BC4CB1CD7EB3700402247 /* HideShowPasswordTextFieldExample */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | 7C8BC4CC1CD7EB3700402247 /* AppDelegate.swift */, 81 | 7C8BC4CE1CD7EB3700402247 /* ViewController.swift */, 82 | 7C8BC4D01CD7EB3700402247 /* Main.storyboard */, 83 | 7C8BC4D31CD7EB3700402247 /* Assets.xcassets */, 84 | 7C8BC4D51CD7EB3700402247 /* LaunchScreen.storyboard */, 85 | 7C8BC4D81CD7EB3700402247 /* Info.plist */, 86 | ); 87 | path = HideShowPasswordTextFieldExample; 88 | sourceTree = ""; 89 | }; 90 | 7C8BC4DE1CD7EB4700402247 /* HideShowPasswordTextField */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 7C8BC4E31CD7ED9100402247 /* ic_eye_closed.png */, 94 | 7C8BC4E41CD7ED9100402247 /* ic_eye_closed@2x.png */, 95 | 7C8BC4E51CD7ED9100402247 /* ic_eye_closed@3x.png */, 96 | 7C8BC4E61CD7ED9100402247 /* ic_eye_open.png */, 97 | 7C8BC4E71CD7ED9100402247 /* ic_eye_open@2x.png */, 98 | 7C8BC4E81CD7ED9100402247 /* ic_eye_open@3x.png */, 99 | 7C8BC4E91CD7ED9100402247 /* ic_password_checkmark.png */, 100 | 7C8BC4EA1CD7ED9100402247 /* ic_password_checkmark@2x.png */, 101 | 7C8BC4EB1CD7ED9100402247 /* ic_password_checkmark@3x.png */, 102 | 7C8BC4DF1CD7EB4700402247 /* HideShowPasswordTextField.swift */, 103 | 7C8BC4E01CD7EB4700402247 /* PasswordToggleVisibilityView.swift */, 104 | ); 105 | name = HideShowPasswordTextField; 106 | path = ../../HideShowPasswordTextField; 107 | sourceTree = ""; 108 | }; 109 | /* End PBXGroup section */ 110 | 111 | /* Begin PBXNativeTarget section */ 112 | 7C8BC4C81CD7EB3700402247 /* HideShowPasswordTextFieldExample */ = { 113 | isa = PBXNativeTarget; 114 | buildConfigurationList = 7C8BC4DB1CD7EB3700402247 /* Build configuration list for PBXNativeTarget "HideShowPasswordTextFieldExample" */; 115 | buildPhases = ( 116 | 7C8BC4C51CD7EB3700402247 /* Sources */, 117 | 7C8BC4C61CD7EB3700402247 /* Frameworks */, 118 | 7C8BC4C71CD7EB3700402247 /* Resources */, 119 | ); 120 | buildRules = ( 121 | ); 122 | dependencies = ( 123 | ); 124 | name = HideShowPasswordTextFieldExample; 125 | productName = HideShowPasswordTextFieldExample; 126 | productReference = 7C8BC4C91CD7EB3700402247 /* HideShowPasswordTextFieldExample.app */; 127 | productType = "com.apple.product-type.application"; 128 | }; 129 | /* End PBXNativeTarget section */ 130 | 131 | /* Begin PBXProject section */ 132 | 7C8BC4C11CD7EB3700402247 /* Project object */ = { 133 | isa = PBXProject; 134 | attributes = { 135 | LastSwiftUpdateCheck = 0730; 136 | LastUpgradeCheck = 1010; 137 | ORGANIZATIONNAME = Guidebook; 138 | TargetAttributes = { 139 | 7C8BC4C81CD7EB3700402247 = { 140 | CreatedOnToolsVersion = 7.3; 141 | }; 142 | }; 143 | }; 144 | buildConfigurationList = 7C8BC4C41CD7EB3700402247 /* Build configuration list for PBXProject "HideShowPasswordTextFieldExample" */; 145 | compatibilityVersion = "Xcode 3.2"; 146 | developmentRegion = English; 147 | hasScannedForEncodings = 0; 148 | knownRegions = ( 149 | English, 150 | en, 151 | Base, 152 | ); 153 | mainGroup = 7C8BC4C01CD7EB3700402247; 154 | productRefGroup = 7C8BC4CA1CD7EB3700402247 /* Products */; 155 | projectDirPath = ""; 156 | projectRoot = ""; 157 | targets = ( 158 | 7C8BC4C81CD7EB3700402247 /* HideShowPasswordTextFieldExample */, 159 | ); 160 | }; 161 | /* End PBXProject section */ 162 | 163 | /* Begin PBXResourcesBuildPhase section */ 164 | 7C8BC4C71CD7EB3700402247 /* Resources */ = { 165 | isa = PBXResourcesBuildPhase; 166 | buildActionMask = 2147483647; 167 | files = ( 168 | 7C8BC4D71CD7EB3700402247 /* LaunchScreen.storyboard in Resources */, 169 | 7C8BC4EF1CD7ED9100402247 /* ic_eye_open.png in Resources */, 170 | 7C8BC4EE1CD7ED9100402247 /* ic_eye_closed@3x.png in Resources */, 171 | 7C8BC4F11CD7ED9100402247 /* ic_eye_open@3x.png in Resources */, 172 | 7C8BC4F41CD7ED9100402247 /* ic_password_checkmark@3x.png in Resources */, 173 | 7C8BC4D41CD7EB3700402247 /* Assets.xcassets in Resources */, 174 | 7C8BC4D21CD7EB3700402247 /* Main.storyboard in Resources */, 175 | 7C8BC4F21CD7ED9100402247 /* ic_password_checkmark.png in Resources */, 176 | 7C8BC4EC1CD7ED9100402247 /* ic_eye_closed.png in Resources */, 177 | 7C8BC4F31CD7ED9100402247 /* ic_password_checkmark@2x.png in Resources */, 178 | 7C8BC4F01CD7ED9100402247 /* ic_eye_open@2x.png in Resources */, 179 | 7C8BC4ED1CD7ED9100402247 /* ic_eye_closed@2x.png in Resources */, 180 | ); 181 | runOnlyForDeploymentPostprocessing = 0; 182 | }; 183 | /* End PBXResourcesBuildPhase section */ 184 | 185 | /* Begin PBXSourcesBuildPhase section */ 186 | 7C8BC4C51CD7EB3700402247 /* Sources */ = { 187 | isa = PBXSourcesBuildPhase; 188 | buildActionMask = 2147483647; 189 | files = ( 190 | 7C8BC4CF1CD7EB3700402247 /* ViewController.swift in Sources */, 191 | 7C8BC4E21CD7EB4700402247 /* PasswordToggleVisibilityView.swift in Sources */, 192 | 7C8BC4CD1CD7EB3700402247 /* AppDelegate.swift in Sources */, 193 | 7C8BC4E11CD7EB4700402247 /* HideShowPasswordTextField.swift in Sources */, 194 | ); 195 | runOnlyForDeploymentPostprocessing = 0; 196 | }; 197 | /* End PBXSourcesBuildPhase section */ 198 | 199 | /* Begin PBXVariantGroup section */ 200 | 7C8BC4D01CD7EB3700402247 /* Main.storyboard */ = { 201 | isa = PBXVariantGroup; 202 | children = ( 203 | 7C8BC4D11CD7EB3700402247 /* Base */, 204 | ); 205 | name = Main.storyboard; 206 | sourceTree = ""; 207 | }; 208 | 7C8BC4D51CD7EB3700402247 /* LaunchScreen.storyboard */ = { 209 | isa = PBXVariantGroup; 210 | children = ( 211 | 7C8BC4D61CD7EB3700402247 /* Base */, 212 | ); 213 | name = LaunchScreen.storyboard; 214 | sourceTree = ""; 215 | }; 216 | /* End PBXVariantGroup section */ 217 | 218 | /* Begin XCBuildConfiguration section */ 219 | 7C8BC4D91CD7EB3700402247 /* Debug */ = { 220 | isa = XCBuildConfiguration; 221 | buildSettings = { 222 | ALWAYS_SEARCH_USER_PATHS = NO; 223 | CLANG_ANALYZER_NONNULL = YES; 224 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 225 | CLANG_CXX_LIBRARY = "libc++"; 226 | CLANG_ENABLE_MODULES = YES; 227 | CLANG_ENABLE_OBJC_ARC = YES; 228 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 229 | CLANG_WARN_BOOL_CONVERSION = YES; 230 | CLANG_WARN_COMMA = YES; 231 | CLANG_WARN_CONSTANT_CONVERSION = YES; 232 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 233 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 234 | CLANG_WARN_EMPTY_BODY = YES; 235 | CLANG_WARN_ENUM_CONVERSION = YES; 236 | CLANG_WARN_INFINITE_RECURSION = YES; 237 | CLANG_WARN_INT_CONVERSION = YES; 238 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 239 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 240 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 241 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 242 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 243 | CLANG_WARN_STRICT_PROTOTYPES = YES; 244 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 245 | CLANG_WARN_UNREACHABLE_CODE = YES; 246 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 247 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 248 | COPY_PHASE_STRIP = NO; 249 | DEBUG_INFORMATION_FORMAT = dwarf; 250 | ENABLE_STRICT_OBJC_MSGSEND = YES; 251 | ENABLE_TESTABILITY = YES; 252 | GCC_C_LANGUAGE_STANDARD = gnu99; 253 | GCC_DYNAMIC_NO_PIC = NO; 254 | GCC_NO_COMMON_BLOCKS = YES; 255 | GCC_OPTIMIZATION_LEVEL = 0; 256 | GCC_PREPROCESSOR_DEFINITIONS = ( 257 | "DEBUG=1", 258 | "$(inherited)", 259 | ); 260 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 261 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 262 | GCC_WARN_UNDECLARED_SELECTOR = YES; 263 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 264 | GCC_WARN_UNUSED_FUNCTION = YES; 265 | GCC_WARN_UNUSED_VARIABLE = YES; 266 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 267 | MTL_ENABLE_DEBUG_INFO = YES; 268 | ONLY_ACTIVE_ARCH = YES; 269 | SDKROOT = iphoneos; 270 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 271 | SWIFT_VERSION = 4.2; 272 | TARGETED_DEVICE_FAMILY = "1,2"; 273 | }; 274 | name = Debug; 275 | }; 276 | 7C8BC4DA1CD7EB3700402247 /* Release */ = { 277 | isa = XCBuildConfiguration; 278 | buildSettings = { 279 | ALWAYS_SEARCH_USER_PATHS = NO; 280 | CLANG_ANALYZER_NONNULL = YES; 281 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 282 | CLANG_CXX_LIBRARY = "libc++"; 283 | CLANG_ENABLE_MODULES = YES; 284 | CLANG_ENABLE_OBJC_ARC = YES; 285 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 286 | CLANG_WARN_BOOL_CONVERSION = YES; 287 | CLANG_WARN_COMMA = YES; 288 | CLANG_WARN_CONSTANT_CONVERSION = YES; 289 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 290 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 291 | CLANG_WARN_EMPTY_BODY = YES; 292 | CLANG_WARN_ENUM_CONVERSION = YES; 293 | CLANG_WARN_INFINITE_RECURSION = YES; 294 | CLANG_WARN_INT_CONVERSION = YES; 295 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 296 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 297 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 298 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 299 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 300 | CLANG_WARN_STRICT_PROTOTYPES = YES; 301 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 302 | CLANG_WARN_UNREACHABLE_CODE = YES; 303 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 304 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 305 | COPY_PHASE_STRIP = NO; 306 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 307 | ENABLE_NS_ASSERTIONS = NO; 308 | ENABLE_STRICT_OBJC_MSGSEND = YES; 309 | GCC_C_LANGUAGE_STANDARD = gnu99; 310 | GCC_NO_COMMON_BLOCKS = YES; 311 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 312 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 313 | GCC_WARN_UNDECLARED_SELECTOR = YES; 314 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 315 | GCC_WARN_UNUSED_FUNCTION = YES; 316 | GCC_WARN_UNUSED_VARIABLE = YES; 317 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 318 | MTL_ENABLE_DEBUG_INFO = NO; 319 | SDKROOT = iphoneos; 320 | SWIFT_COMPILATION_MODE = wholemodule; 321 | SWIFT_VERSION = 4.2; 322 | TARGETED_DEVICE_FAMILY = "1,2"; 323 | VALIDATE_PRODUCT = YES; 324 | }; 325 | name = Release; 326 | }; 327 | 7C8BC4DC1CD7EB3700402247 /* Debug */ = { 328 | isa = XCBuildConfiguration; 329 | buildSettings = { 330 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 331 | INFOPLIST_FILE = HideShowPasswordTextFieldExample/Info.plist; 332 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 333 | PRODUCT_BUNDLE_IDENTIFIER = com.Guidebook.HideShowPasswordTextFieldExample; 334 | PRODUCT_NAME = "$(TARGET_NAME)"; 335 | SWIFT_VERSION = 5.0; 336 | }; 337 | name = Debug; 338 | }; 339 | 7C8BC4DD1CD7EB3700402247 /* Release */ = { 340 | isa = XCBuildConfiguration; 341 | buildSettings = { 342 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 343 | INFOPLIST_FILE = HideShowPasswordTextFieldExample/Info.plist; 344 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 345 | PRODUCT_BUNDLE_IDENTIFIER = com.Guidebook.HideShowPasswordTextFieldExample; 346 | PRODUCT_NAME = "$(TARGET_NAME)"; 347 | SWIFT_VERSION = 5.0; 348 | }; 349 | name = Release; 350 | }; 351 | /* End XCBuildConfiguration section */ 352 | 353 | /* Begin XCConfigurationList section */ 354 | 7C8BC4C41CD7EB3700402247 /* Build configuration list for PBXProject "HideShowPasswordTextFieldExample" */ = { 355 | isa = XCConfigurationList; 356 | buildConfigurations = ( 357 | 7C8BC4D91CD7EB3700402247 /* Debug */, 358 | 7C8BC4DA1CD7EB3700402247 /* Release */, 359 | ); 360 | defaultConfigurationIsVisible = 0; 361 | defaultConfigurationName = Release; 362 | }; 363 | 7C8BC4DB1CD7EB3700402247 /* Build configuration list for PBXNativeTarget "HideShowPasswordTextFieldExample" */ = { 364 | isa = XCConfigurationList; 365 | buildConfigurations = ( 366 | 7C8BC4DC1CD7EB3700402247 /* Debug */, 367 | 7C8BC4DD1CD7EB3700402247 /* Release */, 368 | ); 369 | defaultConfigurationIsVisible = 0; 370 | defaultConfigurationName = Release; 371 | }; 372 | /* End XCConfigurationList section */ 373 | }; 374 | rootObject = 7C8BC4C11CD7EB3700402247 /* Project object */; 375 | } 376 | -------------------------------------------------------------------------------- /Example/HideShowPasswordTextFieldExample/HideShowPasswordTextFieldExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/HideShowPasswordTextFieldExample/HideShowPasswordTextFieldExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // HideShowPasswordTextFieldExample 4 | // 5 | // Created by Mike Sprague on 5/2/16. 6 | // Copyright © 2016 Guidebook. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> 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 throttle down OpenGL ES frame rates. 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 inactive 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 | -------------------------------------------------------------------------------- /Example/HideShowPasswordTextFieldExample/HideShowPasswordTextFieldExample/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 | "idiom" : "ipad", 65 | "size" : "83.5x83.5", 66 | "scale" : "2x" 67 | } 68 | ], 69 | "info" : { 70 | "version" : 1, 71 | "author" : "xcode" 72 | } 73 | } -------------------------------------------------------------------------------- /Example/HideShowPasswordTextFieldExample/HideShowPasswordTextFieldExample/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 | -------------------------------------------------------------------------------- /Example/HideShowPasswordTextFieldExample/HideShowPasswordTextFieldExample/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 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Example/HideShowPasswordTextFieldExample/HideShowPasswordTextFieldExample/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Example/HideShowPasswordTextFieldExample/HideShowPasswordTextFieldExample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // HideShowPasswordTextFieldExample 4 | // 5 | // Created by Mike Sprague on 5/2/16. 6 | // Copyright © 2016 Guidebook. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | @IBOutlet weak var passwordTextField: HideShowPasswordTextField! 13 | 14 | override func viewDidLoad() { 15 | super.viewDidLoad() 16 | // Do any additional setup after loading the view, typically from a nib. 17 | setupPasswordTextField() 18 | } 19 | 20 | override func didReceiveMemoryWarning() { 21 | super.didReceiveMemoryWarning() 22 | // Dispose of any resources that can be recreated. 23 | } 24 | } 25 | 26 | // MARK: HideShowPasswordTextFieldDelegate 27 | // Implementing this delegate is entirely optional. 28 | // It's useful when you want to show the user that their password is valid. 29 | extension ViewController: HideShowPasswordTextFieldDelegate { 30 | func isValidPassword(_ password: String) -> Bool { 31 | return password.count > 7 32 | } 33 | } 34 | 35 | // MARK: Private helpers 36 | extension ViewController { 37 | private func setupPasswordTextField() { 38 | passwordTextField.passwordDelegate = self 39 | passwordTextField.borderStyle = .none 40 | passwordTextField.clearButtonMode = .whileEditing 41 | passwordTextField.layer.borderWidth = 0.5 42 | passwordTextField.layer.borderColor = UIColor(red: 220/255.0, green: 220/255.0, blue: 220/255.0, alpha: 1.0).cgColor 43 | passwordTextField.borderStyle = UITextField.BorderStyle.none 44 | passwordTextField.clipsToBounds = true 45 | passwordTextField.layer.cornerRadius = 0 46 | 47 | passwordTextField.rightView?.tintColor = UIColor(red: 0.204, green: 0.624, blue: 0.847, alpha: 1) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /HideShowPasswordTextField.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |spec| 2 | spec.name = 'HideShowPasswordTextField' 3 | spec.version = '0.3' 4 | spec.summary = 'Password visibility toggle text field' 5 | spec.description = 'An easy to use UITextField subclass that adds a visibility toggle and an optional validation checkmark' 6 | spec.homepage = 'https://github.com/Guidebook/HideShowPasswordTextField' 7 | spec.license = { type: 'MIT', file: 'LICENSE' } 8 | spec.source = { git: 'https://github.com/Guidebook/HideShowPasswordTextField.git', tag: "v#{spec.version}" } 9 | spec.author = { 'Guidebook' => 'developers@guidebook.com', 'Pete Lada' => 'peter@guidebook.com', 'Mike Sprague' => 'mike@guidebook.com', 'Pete Andersen' => 'pandersen@guidebook.com' } 10 | 11 | spec.platform = :ios, '9.0' 12 | spec.frameworks = 'UIKit' 13 | spec.source_files = 'HideShowPasswordTextField/*.{h,m,swift}' 14 | spec.resources = ['HideShowPasswordTextField/*.{png,xib}'] 15 | end 16 | -------------------------------------------------------------------------------- /HideShowPasswordTextField/HideShowPasswordTextField.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HideShowPasswordTextField.swift 3 | // Guidebook 4 | // 5 | // Created by Mike Sprague on 4/15/16. 6 | // 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | protocol HideShowPasswordTextFieldDelegate: class { 13 | func isValidPassword(_ password: String) -> Bool 14 | } 15 | 16 | public class HideShowPasswordTextField: UITextField { 17 | weak var passwordDelegate: HideShowPasswordTextFieldDelegate? 18 | var preferredFont: UIFont? { 19 | didSet { 20 | self.font = nil 21 | if self.isSecureTextEntry { 22 | self.font = self.preferredFont 23 | } 24 | } 25 | } 26 | 27 | override public var isSecureTextEntry: Bool { 28 | didSet { 29 | if !self.isSecureTextEntry { 30 | self.font = nil 31 | self.font = self.preferredFont 32 | } 33 | 34 | // Hack to prevent text from getting cleared when switching secure entry 35 | // https://stackoverflow.com/a/49771445/1417922 36 | if self.isFirstResponder { 37 | _ = self.becomeFirstResponder() 38 | } 39 | } 40 | } 41 | fileprivate var passwordToggleVisibilityView: PasswordToggleVisibilityView! 42 | 43 | override init(frame: CGRect) { 44 | super.init(frame: frame) 45 | setupViews() 46 | } 47 | 48 | required init?(coder aDecoder: NSCoder) { 49 | super.init(coder: aDecoder) 50 | } 51 | 52 | override public func awakeFromNib() { 53 | super.awakeFromNib() 54 | setupViews() 55 | } 56 | 57 | override public func becomeFirstResponder() -> Bool { 58 | // Hack to prevent text from getting cleared when switching secure entry 59 | // https://stackoverflow.com/a/49771445/1417922 60 | let success = super.becomeFirstResponder() 61 | if self.isSecureTextEntry, let text = self.text { 62 | self.text?.removeAll() 63 | self.insertText(text) 64 | } 65 | return success 66 | } 67 | } 68 | 69 | // MARK: UITextFieldDelegate needed calls 70 | // Implement UITextFieldDelegate when you use this, and forward these calls to this class! 71 | extension HideShowPasswordTextField { 72 | func textFieldDidEndEditing(_ textField: UITextField) { 73 | passwordToggleVisibilityView.eyeState = PasswordToggleVisibilityView.EyeState.closed 74 | self.isSecureTextEntry = !isSelected 75 | } 76 | } 77 | 78 | // MARK: PasswordToggleVisibilityDelegate 79 | extension HideShowPasswordTextField: PasswordToggleVisibilityDelegate { 80 | func viewWasToggled(_ passwordToggleVisibilityView: PasswordToggleVisibilityView, isSelected selected: Bool) { 81 | 82 | // hack to fix a bug with padding when switching between secureTextEntry state 83 | let hackString = self.text 84 | self.text = " " 85 | self.text = hackString 86 | 87 | // hack to save our correct font. The order here is VERY finicky 88 | self.isSecureTextEntry = !selected 89 | } 90 | } 91 | 92 | // MARK: Control events 93 | extension HideShowPasswordTextField { 94 | @objc func passwordTextChanged(_ sender: AnyObject) { 95 | if let password = self.text { 96 | passwordToggleVisibilityView.checkmarkVisible = passwordDelegate?.isValidPassword(password) ?? false 97 | } else { 98 | passwordToggleVisibilityView.checkmarkVisible = false 99 | } 100 | } 101 | } 102 | 103 | // MARK: Private helpers 104 | extension HideShowPasswordTextField { 105 | fileprivate func setupViews() { 106 | let toggleFrame = CGRect(x: 0, y: 0, width: 66, height: frame.height) 107 | passwordToggleVisibilityView = PasswordToggleVisibilityView(frame: toggleFrame) 108 | passwordToggleVisibilityView.delegate = self 109 | passwordToggleVisibilityView.checkmarkVisible = false 110 | self.keyboardType = .asciiCapable 111 | self.rightView = passwordToggleVisibilityView 112 | self.font = self.preferredFont 113 | self.addTarget(self, action: #selector(HideShowPasswordTextField.passwordTextChanged(_:)), for: .editingChanged) 114 | 115 | // if we don't do this, the eye flies in on textfield focus! 116 | self.rightView?.frame = self.rightViewRect(forBounds: self.bounds) 117 | 118 | self.rightViewMode = .whileEditing 119 | // left view hack to add padding 120 | self.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 10, height: 3)) 121 | self.leftViewMode = .always 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /HideShowPasswordTextField/PasswordToggleVisibilityView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PasswordToggleVisibilityView.swift 3 | // Guidebook 4 | // 5 | // Created by Mike Sprague on 4/14/16. 6 | // 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | protocol PasswordToggleVisibilityDelegate: class { 13 | func viewWasToggled(_ passwordToggleVisibilityView: PasswordToggleVisibilityView, isSelected selected: Bool) 14 | } 15 | 16 | class PasswordToggleVisibilityView: UIView { 17 | fileprivate let eyeOpenedImage: UIImage 18 | fileprivate let eyeClosedImage: UIImage 19 | fileprivate let checkmarkImage: UIImage 20 | fileprivate let eyeButton: UIButton 21 | fileprivate let checkmarkImageView: UIImageView 22 | weak var delegate: PasswordToggleVisibilityDelegate? 23 | 24 | enum EyeState { 25 | case open 26 | case closed 27 | } 28 | 29 | var eyeState: EyeState { 30 | set { 31 | eyeButton.isSelected = newValue == .open 32 | } 33 | get { 34 | return eyeButton.isSelected ? .open : .closed 35 | } 36 | } 37 | 38 | var checkmarkVisible: Bool { 39 | set { 40 | let isHidden = !newValue 41 | guard checkmarkImageView.isHidden != isHidden else { 42 | return 43 | } 44 | checkmarkImageView.isHidden = isHidden 45 | } 46 | get { 47 | return !checkmarkImageView.isHidden 48 | } 49 | } 50 | 51 | override var tintColor: UIColor! { 52 | didSet { 53 | eyeButton.tintColor = tintColor 54 | checkmarkImageView.tintColor = tintColor 55 | } 56 | } 57 | 58 | override init(frame: CGRect) { 59 | self.eyeOpenedImage = UIImage(named: "ic_eye_open", in: Bundle(for: PasswordToggleVisibilityView.self), compatibleWith: nil)!.withRenderingMode(.alwaysTemplate) 60 | self.eyeClosedImage = UIImage(named: "ic_eye_closed", in: Bundle(for: PasswordToggleVisibilityView.self), compatibleWith: nil)!.withRenderingMode(.alwaysTemplate) 61 | self.checkmarkImage = UIImage(named: "ic_password_checkmark", in: Bundle(for: PasswordToggleVisibilityView.self), compatibleWith: nil)!.withRenderingMode(.alwaysTemplate) 62 | self.eyeButton = UIButton(type: .custom) 63 | self.checkmarkImageView = UIImageView(image: self.checkmarkImage) 64 | super.init(frame: frame) 65 | setupViews() 66 | } 67 | 68 | required init?(coder aDecoder: NSCoder) { 69 | fatalError("Don't use init with coder.") 70 | } 71 | 72 | fileprivate func setupViews() { 73 | let padding: CGFloat = 10 74 | let buttonWidth = (frame.width / 2) - padding 75 | let buttonFrame = CGRect(x: buttonWidth + padding, y: 0, width: buttonWidth, height: frame.height) 76 | eyeButton.frame = buttonFrame 77 | eyeButton.backgroundColor = UIColor.clear 78 | eyeButton.adjustsImageWhenHighlighted = false 79 | eyeButton.setImage(self.eyeClosedImage, for: UIControl.State()) 80 | eyeButton.setImage(self.eyeOpenedImage.withRenderingMode(.alwaysTemplate), for: .selected) 81 | eyeButton.addTarget(self, action: #selector(PasswordToggleVisibilityView.eyeButtonPressed(_:)), for: .touchUpInside) 82 | eyeButton.autoresizingMask = [.flexibleWidth, .flexibleHeight] 83 | eyeButton.tintColor = self.tintColor 84 | self.addSubview(eyeButton) 85 | 86 | let checkmarkImageWidth = (frame.width / 2) - padding 87 | let checkmarkFrame = CGRect(x: padding, y: 0, width: checkmarkImageWidth, height: frame.height) 88 | checkmarkImageView.frame = checkmarkFrame 89 | checkmarkImageView.autoresizingMask = [.flexibleWidth, .flexibleHeight] 90 | checkmarkImageView.contentMode = .center 91 | checkmarkImageView.backgroundColor = UIColor.clear 92 | checkmarkImageView.tintColor = self.tintColor 93 | self.addSubview(checkmarkImageView) 94 | 95 | self.checkmarkImageView.isHidden = true 96 | } 97 | 98 | 99 | @objc func eyeButtonPressed(_ sender: AnyObject) { 100 | eyeButton.isSelected = !eyeButton.isSelected 101 | delegate?.viewWasToggled(self, isSelected: eyeButton.isSelected) 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /HideShowPasswordTextField/ic_eye_closed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guidebook/HideShowPasswordTextField/d85212236651d141ba387b65edcff9940ab894f3/HideShowPasswordTextField/ic_eye_closed.png -------------------------------------------------------------------------------- /HideShowPasswordTextField/ic_eye_closed@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guidebook/HideShowPasswordTextField/d85212236651d141ba387b65edcff9940ab894f3/HideShowPasswordTextField/ic_eye_closed@2x.png -------------------------------------------------------------------------------- /HideShowPasswordTextField/ic_eye_closed@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guidebook/HideShowPasswordTextField/d85212236651d141ba387b65edcff9940ab894f3/HideShowPasswordTextField/ic_eye_closed@3x.png -------------------------------------------------------------------------------- /HideShowPasswordTextField/ic_eye_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guidebook/HideShowPasswordTextField/d85212236651d141ba387b65edcff9940ab894f3/HideShowPasswordTextField/ic_eye_open.png -------------------------------------------------------------------------------- /HideShowPasswordTextField/ic_eye_open@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guidebook/HideShowPasswordTextField/d85212236651d141ba387b65edcff9940ab894f3/HideShowPasswordTextField/ic_eye_open@2x.png -------------------------------------------------------------------------------- /HideShowPasswordTextField/ic_eye_open@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guidebook/HideShowPasswordTextField/d85212236651d141ba387b65edcff9940ab894f3/HideShowPasswordTextField/ic_eye_open@3x.png -------------------------------------------------------------------------------- /HideShowPasswordTextField/ic_password_checkmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guidebook/HideShowPasswordTextField/d85212236651d141ba387b65edcff9940ab894f3/HideShowPasswordTextField/ic_password_checkmark.png -------------------------------------------------------------------------------- /HideShowPasswordTextField/ic_password_checkmark@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guidebook/HideShowPasswordTextField/d85212236651d141ba387b65edcff9940ab894f3/HideShowPasswordTextField/ic_password_checkmark@2x.png -------------------------------------------------------------------------------- /HideShowPasswordTextField/ic_password_checkmark@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guidebook/HideShowPasswordTextField/d85212236651d141ba387b65edcff9940ab894f3/HideShowPasswordTextField/ic_password_checkmark@3x.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Guidebook 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 | # HideShowPasswordTextField 2 | An easy to use `UITextField` subclass that adds a visibility toggle and an optional validation checkmark 3 | 4 | 5 | Created by [@lookatpete](https://twitter.com/lookatpete) (product), [@pklada](https://twitter.com/pklada) (design), and [@miketsprague](https://twitter.com/miketsprague) (code) 6 | 7 | ![gif](https://s3.amazonaws.com/f.cl.ly/items/1E3Y19383s3J3g0b2Y0M/password_gif.gif?v=fc97ac97) 8 | 9 | ## Installation 10 | ### Cocoapods 11 | `pod 'HideShowPasswordTextField', :git => 'https://github.com/Guidebook/HideShowPasswordTextField'` 12 | 13 | ### Manual 14 | Just add the files in `HideShowPasswordTextField/` to your project. 15 | 16 | 17 | ## Usage 18 | * Create a `UITextField` in your xib, and change the class name to `HideShowPasswordTextField`. Or, create it programatically. 19 | * Set `secureTextEntry` to `true`, if you want the password to hide by default. 20 | * [Recommended] Change the border style to None, and add a height constraint of 44 or larger. The assets in this project are optimized for 44px, although larger is fine too. Smaller sizes might have clipping issues on the icons. 21 | * ~Implement `UITextFieldDelegate` and forward `textField shouldChangeCharactersInRange` and `textFieldDidEndEditing` to your password text field (see the example). We have to do this to get the behavior to work right--apple's API doesn't play very nice switching between `secureTextEntry` states.~ 22 | * This step is no longer necessary. 23 | * [Optional] Implement `HideShowPasswordTextFieldDelegate` to show the validation checkbox. 24 | * Customize the textField to your liking (the tint too!)! 25 | --------------------------------------------------------------------------------