├── .gitignore ├── EGTextFieldExample ├── EGTextFieldExample.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── EGTextFieldExample │ ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── ContentView.swift │ └── EGTextFieldExampleApp.swift ├── LICENSE ├── Package.swift ├── README.md └── Sources └── CustomTextField ├── EGTextField.swift └── EGTextFieldConfig.swift /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | /*.xcodeproj 5 | xcuserdata/ 6 | DerivedData/ 7 | .swiftpm/ 8 | .netrc -------------------------------------------------------------------------------- /EGTextFieldExample/EGTextFieldExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 60; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F1F059612D58754800D7AE94 /* EGTextFieldExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1F059602D58754800D7AE94 /* EGTextFieldExampleApp.swift */; }; 11 | F1F059632D58754800D7AE94 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1F059622D58754800D7AE94 /* ContentView.swift */; }; 12 | F1F059652D58754C00D7AE94 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F1F059642D58754C00D7AE94 /* Assets.xcassets */; }; 13 | F1F059702D58759300D7AE94 /* CustomTextField in Frameworks */ = {isa = PBXBuildFile; productRef = F1F0596F2D58759300D7AE94 /* CustomTextField */; }; 14 | /* End PBXBuildFile section */ 15 | 16 | /* Begin PBXFileReference section */ 17 | F1F0595D2D58754800D7AE94 /* EGTextFieldExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = EGTextFieldExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 18 | F1F059602D58754800D7AE94 /* EGTextFieldExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EGTextFieldExampleApp.swift; sourceTree = ""; }; 19 | F1F059622D58754800D7AE94 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 20 | F1F059642D58754C00D7AE94 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 21 | /* End PBXFileReference section */ 22 | 23 | /* Begin PBXFrameworksBuildPhase section */ 24 | F1F0595A2D58754800D7AE94 /* Frameworks */ = { 25 | isa = PBXFrameworksBuildPhase; 26 | buildActionMask = 2147483647; 27 | files = ( 28 | F1F059702D58759300D7AE94 /* CustomTextField in Frameworks */, 29 | ); 30 | runOnlyForDeploymentPostprocessing = 0; 31 | }; 32 | /* End PBXFrameworksBuildPhase section */ 33 | 34 | /* Begin PBXGroup section */ 35 | F1F059542D58754800D7AE94 = { 36 | isa = PBXGroup; 37 | children = ( 38 | F1F0595F2D58754800D7AE94 /* EGTextFieldExample */, 39 | F1F0595E2D58754800D7AE94 /* Products */, 40 | ); 41 | sourceTree = ""; 42 | }; 43 | F1F0595E2D58754800D7AE94 /* Products */ = { 44 | isa = PBXGroup; 45 | children = ( 46 | F1F0595D2D58754800D7AE94 /* EGTextFieldExample.app */, 47 | ); 48 | name = Products; 49 | sourceTree = ""; 50 | }; 51 | F1F0595F2D58754800D7AE94 /* EGTextFieldExample */ = { 52 | isa = PBXGroup; 53 | children = ( 54 | F1F059602D58754800D7AE94 /* EGTextFieldExampleApp.swift */, 55 | F1F059622D58754800D7AE94 /* ContentView.swift */, 56 | F1F059642D58754C00D7AE94 /* Assets.xcassets */, 57 | ); 58 | path = EGTextFieldExample; 59 | sourceTree = ""; 60 | }; 61 | /* End PBXGroup section */ 62 | 63 | /* Begin PBXNativeTarget section */ 64 | F1F0595C2D58754800D7AE94 /* EGTextFieldExample */ = { 65 | isa = PBXNativeTarget; 66 | buildConfigurationList = F1F0596B2D58754C00D7AE94 /* Build configuration list for PBXNativeTarget "EGTextFieldExample" */; 67 | buildPhases = ( 68 | F1F059592D58754800D7AE94 /* Sources */, 69 | F1F0595A2D58754800D7AE94 /* Frameworks */, 70 | F1F0595B2D58754800D7AE94 /* Resources */, 71 | ); 72 | buildRules = ( 73 | ); 74 | dependencies = ( 75 | ); 76 | name = EGTextFieldExample; 77 | packageProductDependencies = ( 78 | F1F0596F2D58759300D7AE94 /* CustomTextField */, 79 | ); 80 | productName = EGTextFieldExample; 81 | productReference = F1F0595D2D58754800D7AE94 /* EGTextFieldExample.app */; 82 | productType = "com.apple.product-type.application"; 83 | }; 84 | /* End PBXNativeTarget section */ 85 | 86 | /* Begin PBXProject section */ 87 | F1F059552D58754800D7AE94 /* Project object */ = { 88 | isa = PBXProject; 89 | attributes = { 90 | BuildIndependentTargetsInParallel = 1; 91 | LastSwiftUpdateCheck = 1510; 92 | LastUpgradeCheck = 1510; 93 | TargetAttributes = { 94 | F1F0595C2D58754800D7AE94 = { 95 | CreatedOnToolsVersion = 15.1; 96 | }; 97 | }; 98 | }; 99 | buildConfigurationList = F1F059582D58754800D7AE94 /* Build configuration list for PBXProject "EGTextFieldExample" */; 100 | compatibilityVersion = "Xcode 14.0"; 101 | developmentRegion = en; 102 | hasScannedForEncodings = 0; 103 | knownRegions = ( 104 | en, 105 | Base, 106 | ); 107 | mainGroup = F1F059542D58754800D7AE94; 108 | packageReferences = ( 109 | F1F0596E2D58759300D7AE94 /* XCLocalSwiftPackageReference ".." */, 110 | ); 111 | productRefGroup = F1F0595E2D58754800D7AE94 /* Products */; 112 | projectDirPath = ""; 113 | projectRoot = ""; 114 | targets = ( 115 | F1F0595C2D58754800D7AE94 /* EGTextFieldExample */, 116 | ); 117 | }; 118 | /* End PBXProject section */ 119 | 120 | /* Begin PBXResourcesBuildPhase section */ 121 | F1F0595B2D58754800D7AE94 /* Resources */ = { 122 | isa = PBXResourcesBuildPhase; 123 | buildActionMask = 2147483647; 124 | files = ( 125 | F1F059652D58754C00D7AE94 /* Assets.xcassets in Resources */, 126 | ); 127 | runOnlyForDeploymentPostprocessing = 0; 128 | }; 129 | /* End PBXResourcesBuildPhase section */ 130 | 131 | /* Begin PBXSourcesBuildPhase section */ 132 | F1F059592D58754800D7AE94 /* Sources */ = { 133 | isa = PBXSourcesBuildPhase; 134 | buildActionMask = 2147483647; 135 | files = ( 136 | F1F059632D58754800D7AE94 /* ContentView.swift in Sources */, 137 | F1F059612D58754800D7AE94 /* EGTextFieldExampleApp.swift in Sources */, 138 | ); 139 | runOnlyForDeploymentPostprocessing = 0; 140 | }; 141 | /* End PBXSourcesBuildPhase section */ 142 | 143 | /* Begin XCBuildConfiguration section */ 144 | F1F059692D58754C00D7AE94 /* Debug */ = { 145 | isa = XCBuildConfiguration; 146 | buildSettings = { 147 | ALWAYS_SEARCH_USER_PATHS = NO; 148 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 149 | CLANG_ANALYZER_NONNULL = YES; 150 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 151 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 152 | CLANG_ENABLE_MODULES = YES; 153 | CLANG_ENABLE_OBJC_ARC = YES; 154 | CLANG_ENABLE_OBJC_WEAK = YES; 155 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 156 | CLANG_WARN_BOOL_CONVERSION = YES; 157 | CLANG_WARN_COMMA = YES; 158 | CLANG_WARN_CONSTANT_CONVERSION = YES; 159 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 160 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 161 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 162 | CLANG_WARN_EMPTY_BODY = YES; 163 | CLANG_WARN_ENUM_CONVERSION = YES; 164 | CLANG_WARN_INFINITE_RECURSION = YES; 165 | CLANG_WARN_INT_CONVERSION = YES; 166 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 167 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 168 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 169 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 170 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 171 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 172 | CLANG_WARN_STRICT_PROTOTYPES = YES; 173 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 174 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 175 | CLANG_WARN_UNREACHABLE_CODE = YES; 176 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 177 | COPY_PHASE_STRIP = NO; 178 | DEBUG_INFORMATION_FORMAT = dwarf; 179 | ENABLE_STRICT_OBJC_MSGSEND = YES; 180 | ENABLE_TESTABILITY = YES; 181 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 182 | GCC_C_LANGUAGE_STANDARD = gnu17; 183 | GCC_DYNAMIC_NO_PIC = NO; 184 | GCC_NO_COMMON_BLOCKS = YES; 185 | GCC_OPTIMIZATION_LEVEL = 0; 186 | GCC_PREPROCESSOR_DEFINITIONS = ( 187 | "DEBUG=1", 188 | "$(inherited)", 189 | ); 190 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 191 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 192 | GCC_WARN_UNDECLARED_SELECTOR = YES; 193 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 194 | GCC_WARN_UNUSED_FUNCTION = YES; 195 | GCC_WARN_UNUSED_VARIABLE = YES; 196 | IPHONEOS_DEPLOYMENT_TARGET = 17.2; 197 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 198 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 199 | MTL_FAST_MATH = YES; 200 | ONLY_ACTIVE_ARCH = YES; 201 | SDKROOT = iphoneos; 202 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; 203 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 204 | }; 205 | name = Debug; 206 | }; 207 | F1F0596A2D58754C00D7AE94 /* Release */ = { 208 | isa = XCBuildConfiguration; 209 | buildSettings = { 210 | ALWAYS_SEARCH_USER_PATHS = NO; 211 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 212 | CLANG_ANALYZER_NONNULL = YES; 213 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 214 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 215 | CLANG_ENABLE_MODULES = YES; 216 | CLANG_ENABLE_OBJC_ARC = YES; 217 | CLANG_ENABLE_OBJC_WEAK = YES; 218 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 219 | CLANG_WARN_BOOL_CONVERSION = YES; 220 | CLANG_WARN_COMMA = YES; 221 | CLANG_WARN_CONSTANT_CONVERSION = YES; 222 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 223 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 224 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 225 | CLANG_WARN_EMPTY_BODY = YES; 226 | CLANG_WARN_ENUM_CONVERSION = YES; 227 | CLANG_WARN_INFINITE_RECURSION = YES; 228 | CLANG_WARN_INT_CONVERSION = YES; 229 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 230 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 231 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 232 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 233 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 234 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 235 | CLANG_WARN_STRICT_PROTOTYPES = YES; 236 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 237 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 238 | CLANG_WARN_UNREACHABLE_CODE = YES; 239 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 240 | COPY_PHASE_STRIP = NO; 241 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 242 | ENABLE_NS_ASSERTIONS = NO; 243 | ENABLE_STRICT_OBJC_MSGSEND = YES; 244 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 245 | GCC_C_LANGUAGE_STANDARD = gnu17; 246 | GCC_NO_COMMON_BLOCKS = YES; 247 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 248 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 249 | GCC_WARN_UNDECLARED_SELECTOR = YES; 250 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 251 | GCC_WARN_UNUSED_FUNCTION = YES; 252 | GCC_WARN_UNUSED_VARIABLE = YES; 253 | IPHONEOS_DEPLOYMENT_TARGET = 17.2; 254 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 255 | MTL_ENABLE_DEBUG_INFO = NO; 256 | MTL_FAST_MATH = YES; 257 | SDKROOT = iphoneos; 258 | SWIFT_COMPILATION_MODE = wholemodule; 259 | VALIDATE_PRODUCT = YES; 260 | }; 261 | name = Release; 262 | }; 263 | F1F0596C2D58754C00D7AE94 /* Debug */ = { 264 | isa = XCBuildConfiguration; 265 | buildSettings = { 266 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 267 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 268 | CODE_SIGN_STYLE = Automatic; 269 | CURRENT_PROJECT_VERSION = 1; 270 | DEVELOPMENT_TEAM = BUJ3SV57CM; 271 | ENABLE_PREVIEWS = YES; 272 | GENERATE_INFOPLIST_FILE = YES; 273 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 274 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 275 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 276 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 277 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 278 | LD_RUNPATH_SEARCH_PATHS = ( 279 | "$(inherited)", 280 | "@executable_path/Frameworks", 281 | ); 282 | MARKETING_VERSION = 1.0; 283 | PRODUCT_BUNDLE_IDENTIFIER = com.esatgozcu.egtextfieldexample.EGTextFieldExample; 284 | PRODUCT_NAME = "$(TARGET_NAME)"; 285 | SWIFT_EMIT_LOC_STRINGS = YES; 286 | SWIFT_VERSION = 5.0; 287 | TARGETED_DEVICE_FAMILY = "1,2"; 288 | }; 289 | name = Debug; 290 | }; 291 | F1F0596D2D58754C00D7AE94 /* Release */ = { 292 | isa = XCBuildConfiguration; 293 | buildSettings = { 294 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 295 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 296 | CODE_SIGN_STYLE = Automatic; 297 | CURRENT_PROJECT_VERSION = 1; 298 | DEVELOPMENT_TEAM = BUJ3SV57CM; 299 | ENABLE_PREVIEWS = YES; 300 | GENERATE_INFOPLIST_FILE = YES; 301 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 302 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 303 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 304 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 305 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 306 | LD_RUNPATH_SEARCH_PATHS = ( 307 | "$(inherited)", 308 | "@executable_path/Frameworks", 309 | ); 310 | MARKETING_VERSION = 1.0; 311 | PRODUCT_BUNDLE_IDENTIFIER = com.esatgozcu.egtextfieldexample.EGTextFieldExample; 312 | PRODUCT_NAME = "$(TARGET_NAME)"; 313 | SWIFT_EMIT_LOC_STRINGS = YES; 314 | SWIFT_VERSION = 5.0; 315 | TARGETED_DEVICE_FAMILY = "1,2"; 316 | }; 317 | name = Release; 318 | }; 319 | /* End XCBuildConfiguration section */ 320 | 321 | /* Begin XCConfigurationList section */ 322 | F1F059582D58754800D7AE94 /* Build configuration list for PBXProject "EGTextFieldExample" */ = { 323 | isa = XCConfigurationList; 324 | buildConfigurations = ( 325 | F1F059692D58754C00D7AE94 /* Debug */, 326 | F1F0596A2D58754C00D7AE94 /* Release */, 327 | ); 328 | defaultConfigurationIsVisible = 0; 329 | defaultConfigurationName = Release; 330 | }; 331 | F1F0596B2D58754C00D7AE94 /* Build configuration list for PBXNativeTarget "EGTextFieldExample" */ = { 332 | isa = XCConfigurationList; 333 | buildConfigurations = ( 334 | F1F0596C2D58754C00D7AE94 /* Debug */, 335 | F1F0596D2D58754C00D7AE94 /* Release */, 336 | ); 337 | defaultConfigurationIsVisible = 0; 338 | defaultConfigurationName = Release; 339 | }; 340 | /* End XCConfigurationList section */ 341 | 342 | /* Begin XCLocalSwiftPackageReference section */ 343 | F1F0596E2D58759300D7AE94 /* XCLocalSwiftPackageReference ".." */ = { 344 | isa = XCLocalSwiftPackageReference; 345 | relativePath = ..; 346 | }; 347 | /* End XCLocalSwiftPackageReference section */ 348 | 349 | /* Begin XCSwiftPackageProductDependency section */ 350 | F1F0596F2D58759300D7AE94 /* CustomTextField */ = { 351 | isa = XCSwiftPackageProductDependency; 352 | productName = CustomTextField; 353 | }; 354 | /* End XCSwiftPackageProductDependency section */ 355 | }; 356 | rootObject = F1F059552D58754800D7AE94 /* Project object */; 357 | } 358 | -------------------------------------------------------------------------------- /EGTextFieldExample/EGTextFieldExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /EGTextFieldExample/EGTextFieldExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /EGTextFieldExample/EGTextFieldExample/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /EGTextFieldExample/EGTextFieldExample/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "platform" : "ios", 6 | "size" : "1024x1024" 7 | } 8 | ], 9 | "info" : { 10 | "author" : "xcode", 11 | "version" : 1 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /EGTextFieldExample/EGTextFieldExample/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /EGTextFieldExample/EGTextFieldExample/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // EGTextFieldExample 4 | // 5 | // Created by Esat Gözcü on 9.02.2025. 6 | // 7 | 8 | import SwiftUI 9 | import CustomTextField 10 | 11 | struct ContentView: View { 12 | @State private var password: String = "Test FocusState" 13 | @FocusState private var isPasswordFieldFocused: Bool 14 | 15 | var body: some View { 16 | VStack { 17 | EGTextField(text: $password) 18 | .setSecureText(true) 19 | .setBorderColor(isPasswordFieldFocused ? .gray : .gray.opacity(0.1)) 20 | .focused($isPasswordFieldFocused) 21 | Button("Close Keyboard") { 22 | isPasswordFieldFocused = false 23 | } 24 | .padding() 25 | } 26 | } 27 | } 28 | 29 | #Preview { 30 | ContentView() 31 | } 32 | -------------------------------------------------------------------------------- /EGTextFieldExample/EGTextFieldExample/EGTextFieldExampleApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EGTextFieldExampleApp.swift 3 | // EGTextFieldExample 4 | // 5 | // Created by Esat Gözcü on 9.02.2025. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct EGTextFieldExampleApp: App { 12 | var body: some Scene { 13 | WindowGroup { 14 | ContentView() 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Esat GÖZCÜ 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 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.7 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "CustomTextField", 8 | products: [ 9 | // Products define the executables and libraries a package produces, and make them visible to other packages. 10 | .library( 11 | name: "CustomTextField", 12 | targets: ["CustomTextField"]), 13 | ], 14 | dependencies: [ 15 | // Dependencies declare other packages that this package depends on. 16 | // .package(url: /* package url */, from: "1.0.0"), 17 | ], 18 | targets: [ 19 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 20 | // Targets can depend on other targets in this package, and on products in packages this package depends on. 21 | .target( 22 | name: "CustomTextField", 23 | dependencies: []) 24 | ] 25 | ) 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Logo 3 |

4 | 5 |

6 | Swift 5.6 7 | SwiftUI 8 | MIT License 9 | 10 | 11 | 12 |

13 | 14 | # EGTextField - SwiftUI Custom TextField 15 | 16 | This repository developed with only swiftUI, there is no UIViewRepresentable. 17 | 18 | #### Version Compatibility 19 | 20 | - iOS 15.0+ 21 | 22 | #### Swift Package Manager 23 | 24 | CustomTextfield is available through [Swift Package Manager](https://swift.org/package-manager/). Add CustomTextField as a dependency to your `Package.swift`: 25 | 26 | ```Swift 27 | .package(url: "https://github.com/esatgozcu/SwiftUI-Custom-TextField", from: "main") 28 | ``` 29 | 30 | ## Customize config 31 | 32 | You can set your [config](Sources/CustomTextField/EGTextFieldConfig.swift) properties in @main so you don't need to set every time. 33 | 34 | ```Swift 35 | @main 36 | struct ExampleApp: App { 37 | init() { 38 | let shared = EGTextFieldConfig.shared 39 | shared.defaultTextColor = .black 40 | shared.darkModeTextColor = .white 41 | shared.defaultTitleColor = .black 42 | shared.darkModeTitleColor = .white 43 | shared.titleFont = .body 44 | shared.borderType = .line 45 | ... 46 | } 47 | var body: some Scene { 48 | WindowGroup { 49 | ContentView() 50 | } 51 | } 52 | } 53 | ``` 54 | 55 | ## Dark Mode 56 | 57 | Dark mode ability is available. You don't need to consider this issue. If you want to change default color you can set in [config](Sources/CustomTextField/EGTextFieldConfig.swift) file. 58 | 59 | #### Default initialize 60 | 61 | ```swift 62 | @State var text = "Esat Gozcu" 63 | 64 | EGTextField(text: $text) 65 | .setTitleText("Title") 66 | ``` 67 | #### Light 68 | Light Mode 69 | 70 | #### Dark 71 | Dark Mode 72 | 73 | ## Examples 74 | 75 | #### Default 76 | 77 | ```swift 78 | @State var text = "Esat Gozcu" 79 | 80 | EGTextField(text: $text) 81 | ``` 82 | 83 | Default 84 | 85 | #### Line Border 86 | 87 | ```swift 88 | @State var text = "Esat Gozcu" 89 | 90 | EGTextField(text: $text) 91 | .setBorderType(.line) 92 | ``` 93 | 94 | Line Border 95 | 96 | #### Title 97 | 98 | ```swift 99 | @State var text = "Esat Gozcu" 100 | 101 | EGTextField(text: $text) 102 | .setTitleText("Name") 103 | .setTitleColor(.blue) 104 | .setTitleFont(.body) 105 | ``` 106 | 107 | Title 108 | 109 | #### PlaceHolder 110 | 111 | ```swift 112 | @State var text = "" 113 | 114 | EGTextField(text: $text) 115 | .setPlaceHolderText("Enter a name") 116 | ``` 117 | 118 | PlaceHolder 119 | 120 | Also if you want you can change placeholder color 121 | 122 | ```swift 123 | @State var text = "" 124 | 125 | EGTextField(text: $text) 126 | .setPlaceHolderText("Enter a name") 127 | .setPlaceHolderTextColor(Color.gray) 128 | ``` 129 | 130 | #### Disable 131 | 132 | ```swift 133 | @State var text = "Esat Gozcu" 134 | @State var disable = true 135 | 136 | EGTextField(text: $text) 137 | .setDisable($disable) 138 | .setDisableColor(Color.gray.opacity(0.2)) 139 | ``` 140 | 141 | Disable 142 | 143 | 144 | #### Bottom Error 145 | 146 | ```swift 147 | @State var text = "Esat Gozcu" 148 | @State var error = true 149 | @State var errorText = "Your name is not matched" 150 | 151 | EGTextField(text: $text) 152 | .setError(errorText: $errorText, error: $error) 153 | ``` 154 | 155 | Bottom Error 156 | 157 | 158 | #### Trailing Image 159 | 160 | ```swift 161 | @State var text = "Esat Gozcu" 162 | 163 | EGTextField(text: $text) 164 | .setTrailingImage(Image(systemName: "qrcode"), click: { 165 | print("qr image tapped") 166 | }) 167 | ``` 168 | 169 | Trailing Image 170 | 171 | You can also set image foreground color. 172 | 173 | ```swift 174 | EGTextField(text: $text) 175 | .setTrailingImageForegroundColor(.black) 176 | .setDarkModeTrailingImageForegroundColor(.white) 177 | ``` 178 | 179 | ⚠️ Warning: If you do not use system image. When you add your image, you have to set your 'Render as -> Template Image'. Otherwise you can not use this foreground color feature. 180 | 181 | #### Secure Text 182 | 183 | ```swift 184 | @State var text = "Esat Gozcu" 185 | 186 | EGTextField(text: $text) 187 | .setSecureText(true) 188 | ``` 189 | 190 | Secure Text Close 191 | Secure Text Open 192 | 193 | Secure text images can be changed 194 | 195 | ```swift 196 | @State var text = "Esat Gozcu" 197 | 198 | EGTextField(text: $text) 199 | .setSecureText(true) 200 | .setSecureTextImages(open : Image(systemName: "eye.fill"), 201 | close: Image(systemName: "eye.slash.fill")) 202 | ``` 203 | 204 | #### Max Count 205 | 206 | ```swift 207 | @State var text = "Esat Gozcu" 208 | 209 | EGTextField(text: $text) 210 | .setMaxCount(8) 211 | ``` 212 | 213 | Max Count 214 | 215 | #### Truncation Mode 216 | 217 | ```swift 218 | @State var text = "esat1feyk23mqjyefycrfk862x78cyk2sy9l0t8rt6c" 219 | 220 | EGTextField(text: $text) 221 | .setTruncateMode(.middle) 222 | ``` 223 | 224 | Truncation Mode 225 | 226 | #### Border Color and Width 227 | 228 | ```swift 229 | @State var text = "Esat Gozcu" 230 | 231 | EGTextField(text: $text) 232 | .setBorderColor(.orange) 233 | .setBorderWidth(1.0) 234 | ``` 235 | 236 | Border Color 237 | 238 | #### Text Color 239 | 240 | ```swift 241 | @State var text = "Esat Gozcu" 242 | 243 | EGTextField(text: $text) 244 | .setTextColor(.blue) 245 | ``` 246 | 247 | Text Color 248 | 249 | #### Background Color 250 | 251 | ```swift 252 | @State var text = "Esat Gozcu" 253 | 254 | EGTextField(text: $text) 255 | .setBackgroundColor(Color.black) 256 | .setTextColor(Color.white) 257 | ``` 258 | 259 | Background Color 260 | 261 | #### Corner Radius 262 | 263 | ```swift 264 | @State var text = "Esat Gozcu" 265 | 266 | EGTextField(text: $text) 267 | .setCornerRadius(20.0) 268 | ``` 269 | 270 | Corner Radius 271 | 272 | 273 | #### Disable Auto Correction 274 | 275 | ```swift 276 | @State var text = "Esat Gozcu" 277 | 278 | EGTextField(text: $text) 279 | .setDisableAutoCorrection(true) 280 | ``` 281 | 282 | #### Set Height 283 | 284 | ```swift 285 | @State var text = "Esat Gozcu" 286 | 287 | EGTextField(text: $text) 288 | .setTextFieldHeight(45) 289 | ``` 290 | 291 | #### Focused Border Color 292 | 293 | ```swift 294 | @State var text = "Esat Gozcu" 295 | 296 | EGTextField(text: $text) 297 | .setFocusedBorderColorEnable(true) 298 | ``` 299 | 300 | Normal 301 | 302 | Focused 303 | 304 | You can change the colors if you want. 305 | 306 | ```swift 307 | @State var text = "Esat Gozcu" 308 | 309 | EGTextField(text: $text) 310 | .setFocusedBorderColorEnable(true) 311 | .setFocusedBorderColor(.black) 312 | .setDarkModeFocusedBorderColor(.white) 313 | ``` 314 | 315 | ⚠️ Warning: This feauture is not working on secureField. 316 |
317 | 318 | EGTextField has been designed with SwiftUI’s flexibility in mind, allowing the use of features it does not natively include. 319 | Alternatively, you can try the following approach. 320 | 321 | ```swift 322 | @State private var password: String = "Test FocusState" 323 | @FocusState private var isPasswordFieldFocused: Bool 324 | 325 | var body: some View { 326 | VStack { 327 | EGTextField(text: $password) 328 | .setSecureText(true) 329 | .setBorderColor(isPasswordFieldFocused ? .gray : .gray.opacity(0.1)) 330 | .focused($isPasswordFieldFocused) 331 | Button("Close Keyboard") { 332 | isPasswordFieldFocused = false 333 | } 334 | .padding() 335 | } 336 | } 337 | ``` 338 | 339 | ⚠️ Warning: SecureTextField requires iOS 15 or later. 340 | 341 |
342 | 343 | ### License 344 | 345 | This framework is provided under the MIT License. Feel free to modify and use it in your projects. 346 | 347 | ### Contributions 348 | 349 | Contributions are welcome! If you have ideas or improvements, feel free to: 350 | 351 | - Fork the repository. 352 | - Submit a pull request. 353 | - Report issues or feature requests in the Issues tab. 354 | 355 | Thank you for contributing! 😊 356 | -------------------------------------------------------------------------------- /Sources/CustomTextField/EGTextField.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EGTextField.swift 3 | // EGTextField 4 | // 5 | // Created by Esat Gözcü on 2023/03/30. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @available(iOS 13.0, *) 11 | public struct EGTextField: View { 12 | 13 | @Environment(\.colorScheme) var colorScheme: ColorScheme 14 | @State private var trailingImage : Image? 15 | @State private var secureText = false{ 16 | didSet{ 17 | if secureText{ 18 | isFocused = false 19 | } 20 | } 21 | } 22 | @State var isFocused = false 23 | private var text: Binding 24 | private var disable: Binding? 25 | private var error: Binding? 26 | private var errorText: Binding? 27 | private var isSecureText: Bool = false 28 | private var titleText: String? 29 | private var placeHolderText: String = "" 30 | private var trailingImageClick: (() -> Void)? 31 | private var secureTextImageOpen : Image? = Image(systemName: "eye.fill") 32 | private var secureTextImageClose : Image? = Image(systemName: "eye.slash.fill") 33 | private var maxCount: Int? 34 | private var truncationMode: Text.TruncationMode = Text.TruncationMode.tail 35 | //Text Color 36 | private var defaultTextColor = EGTextFieldConfig.shared.defaultTextColor 37 | private var darkModeTextColor = EGTextFieldConfig.shared.darkModeTextColor 38 | //Title Color 39 | private var defaultTitleColor = EGTextFieldConfig.shared.defaultTitleColor 40 | private var darkModeTitleColor = EGTextFieldConfig.shared.darkModeTitleColor 41 | //PlaceHolder Text Color 42 | private var defaultPlaceHolderTextColor = EGTextFieldConfig.shared.defaultPlaceHolderTextColor 43 | private var darkModePlaceHolderTextColor = EGTextFieldConfig.shared.darkModePlaceHolderTextColor 44 | //Disable Color 45 | private var defaultDisableColor = EGTextFieldConfig.shared.defaultDisableColor 46 | private var darkModeDisableColor = EGTextFieldConfig.shared.darkModeDisableColor 47 | //Background Color 48 | private var defaultBackgroundColor = EGTextFieldConfig.shared.defaultBackgroundColor 49 | private var darkModeBackgroundColor = EGTextFieldConfig.shared.darkModeBackgroundColor 50 | //Error Text Color 51 | private var defaultErrorTextColor = EGTextFieldConfig.shared.defaultErrorTextColor 52 | private var darkModeErrorTextColor = EGTextFieldConfig.shared.darkModeErrorTextColor 53 | //Border Color 54 | private var defaultBorderColor = EGTextFieldConfig.shared.defaultBorderColor 55 | private var darkModeBorderColor = EGTextFieldConfig.shared.darkModeBorderColor 56 | //Trailing Image Color 57 | private var defaultTrailingImageForegroundColor = EGTextFieldConfig.shared.defaultTrailingImageForegroundColor 58 | private var darkModeTrailingImageForegroundColor = EGTextFieldConfig.shared.darkModeTrailingImageForegroundColor 59 | //Focused Border Color 60 | private var focusedBorderColorEnable = EGTextFieldConfig.shared.focusedBorderColorEnable 61 | private var defaultFocusedBorderColor = EGTextFieldConfig.shared.defaultFocusedBorderColor 62 | private var darkModeFocusedBorderColor = EGTextFieldConfig.shared.darkModeFocusedBorderColor 63 | //Font 64 | private var textFont = EGTextFieldConfig.shared.textFont 65 | private var titleFont = EGTextFieldConfig.shared.titleFont 66 | private var errorFont = EGTextFieldConfig.shared.errorFont 67 | private var placeHolderFont = EGTextFieldConfig.shared.placeHolderFont 68 | //Default 69 | private var borderWidth = EGTextFieldConfig.shared.borderWidth 70 | private var cornerRadius = EGTextFieldConfig.shared.cornerRadius 71 | private var borderType = EGTextFieldConfig.shared.borderType 72 | private var disableAutoCorrection = EGTextFieldConfig.shared.disableAutoCorrection 73 | private var textFieldHeight = EGTextFieldConfig.shared.textFieldHeight 74 | 75 | public init(text: Binding) { 76 | self.text = text 77 | } 78 | 79 | public var body: some View{ 80 | VStack(spacing: 8){ 81 | //Title 82 | if let titleText{ 83 | Text(titleText) 84 | .font(titleFont) 85 | .foregroundColor(getTitleTextColor()) 86 | .frame(maxWidth: .infinity, alignment: .leading) 87 | } 88 | VStack(spacing: 0){ 89 | //TextField 90 | HStack(spacing: 0){ 91 | secureAnyView() 92 | .placeholder(when: text.wrappedValue.isEmpty, placeholder: { 93 | Text(placeHolderText) 94 | .foregroundColor(getPlaceHolderTextColor()) 95 | .font(placeHolderFont) 96 | }) 97 | .font(textFont) 98 | .frame(maxWidth: .infinity) 99 | .frame(height: textFieldHeight) 100 | .foregroundColor(getTextColor()) 101 | .disabled(disable?.wrappedValue ?? false) 102 | .padding([.leading, .trailing], borderType == .square ? 12 : 1) 103 | .disableAutocorrection(disableAutoCorrection) 104 | .onReceive(text.wrappedValue.publisher.collect()) { 105 | if let maxCount{ 106 | let s = String($0.prefix(maxCount)) 107 | if text.wrappedValue != s && (maxCount != 0){ 108 | text.wrappedValue = s 109 | } 110 | } 111 | } 112 | .truncationMode(truncationMode) 113 | .background(Color.clear) 114 | trailingImage? 115 | .resizable() 116 | .scaledToFit() 117 | .foregroundColor(getTrailingImageForegroundColor()) 118 | .frame(width: 25, height: 25) 119 | .padding(.trailing, 12) 120 | .onTapGesture { 121 | if !isSecureText{ 122 | trailingImageClick?() 123 | } 124 | else{ 125 | secureText.toggle() 126 | trailingImage = secureText ? secureTextImageClose : secureTextImageOpen 127 | } 128 | } 129 | .disabled(disable?.wrappedValue ?? false) 130 | }.background( 131 | RoundedRectangle(cornerRadius: getCornerRadius()) 132 | .stroke(getBorderColor(), lineWidth: getBorderWidth(type: .square)) 133 | .background(getBackgroundColor().cornerRadius(getCornerRadius())) 134 | ) 135 | //Bottom Line 136 | if borderType == .line{ 137 | Rectangle() 138 | .frame(height: getBorderWidth(type: .line)) 139 | .foregroundColor(getBorderColor()) 140 | } 141 | } 142 | //Bottom text 143 | if let error = error?.wrappedValue{ 144 | if error{ 145 | Text(errorText?.wrappedValue ?? "") 146 | .font(errorFont) 147 | .foregroundColor(getErrorTextColor()) 148 | .frame(maxWidth: .infinity, alignment: .leading) 149 | } 150 | } 151 | } 152 | } 153 | private func secureAnyView() -> AnyView{ 154 | if !secureText{ 155 | return AnyView(TextField("", text: text, onEditingChanged: { changed in 156 | if changed{ 157 | isFocused = true 158 | } 159 | else{ 160 | isFocused = false 161 | } 162 | })) 163 | } 164 | else{ 165 | return AnyView(SecureField("", text: text)) 166 | } 167 | } 168 | private func getBorderColor() -> Color{ 169 | if error?.wrappedValue ?? false { 170 | return getErrorTextColor() 171 | } 172 | else{ 173 | if colorScheme == .light{ 174 | if isFocused && focusedBorderColorEnable{ 175 | return defaultFocusedBorderColor 176 | } 177 | else{ 178 | return defaultBorderColor 179 | } 180 | } 181 | else{ 182 | if isFocused && focusedBorderColorEnable{ 183 | return darkModeFocusedBorderColor 184 | } 185 | else{ 186 | return darkModeBorderColor 187 | } 188 | } 189 | } 190 | } 191 | private func getBackgroundColor() -> Color{ 192 | if disable?.wrappedValue ?? false{ 193 | return colorScheme == .light ? defaultDisableColor : darkModeDisableColor 194 | } 195 | else{ 196 | return colorScheme == .light ? defaultBackgroundColor : darkModeBackgroundColor 197 | } 198 | } 199 | private func getTextColor() -> Color{ 200 | return colorScheme == .light ? defaultTextColor : darkModeTextColor 201 | } 202 | private func getErrorTextColor() -> Color{ 203 | return colorScheme == .light ? defaultErrorTextColor : darkModeErrorTextColor 204 | } 205 | private func getPlaceHolderTextColor() -> Color{ 206 | return colorScheme == .light ? defaultPlaceHolderTextColor : darkModePlaceHolderTextColor 207 | } 208 | private func getTitleTextColor() -> Color{ 209 | return colorScheme == .light ? defaultTitleColor : darkModeTitleColor 210 | } 211 | private func getBorderWidth(type: BorderType) -> CGFloat{ 212 | if type == .square{ 213 | return borderType == .square ? borderWidth : 0.0 214 | } 215 | else{ 216 | return borderWidth 217 | } 218 | } 219 | private func getCornerRadius() -> CGFloat{ 220 | return borderType == .square ? cornerRadius : 0.0 221 | } 222 | private func getTrailingImageForegroundColor() -> Color{ 223 | return colorScheme == .light ? defaultTrailingImageForegroundColor : darkModeTrailingImageForegroundColor 224 | } 225 | } 226 | 227 | @available(iOS 13.0, *) 228 | extension EGTextField{ 229 | public func setTextColor(_ color: Color) -> Self{ 230 | var copy = self 231 | copy.defaultTextColor = color 232 | return copy 233 | } 234 | public func setDarkModeTextColor(_ color: Color) -> Self{ 235 | var copy = self 236 | copy.darkModeTextColor = color 237 | return copy 238 | } 239 | public func setTitleText(_ titleText: String) -> Self{ 240 | var copy = self 241 | copy.titleText = titleText 242 | return copy 243 | } 244 | public func setTitleColor(_ titleColor: Color) -> Self{ 245 | var copy = self 246 | copy.defaultTitleColor = titleColor 247 | return copy 248 | } 249 | public func setDarkModeTitleColor(_ titleColor: Color) -> Self{ 250 | var copy = self 251 | copy.darkModeTitleColor = titleColor 252 | return copy 253 | } 254 | public func setTitleFont(_ titleFont: Font) -> Self{ 255 | var copy = self 256 | copy.titleFont = titleFont 257 | return copy 258 | } 259 | public func setPlaceHolderText(_ placeHolderText: String) -> Self { 260 | var copy = self 261 | copy.placeHolderText = placeHolderText 262 | return copy 263 | } 264 | public func setPlaceHolderFont(_ placeHolderFont: Font) -> Self{ 265 | var copy = self 266 | copy.placeHolderFont = placeHolderFont 267 | return copy 268 | } 269 | public func setPlaceHolderTextColor(_ color: Color) -> Self{ 270 | var copy = self 271 | copy.defaultPlaceHolderTextColor = color 272 | return copy 273 | } 274 | public func setDarkModePlaceHolderTextColor(_ color: Color) -> Self{ 275 | var copy = self 276 | copy.darkModePlaceHolderTextColor = color 277 | return copy 278 | } 279 | public func setDisable(_ disable: Binding) -> Self{ 280 | var copy = self 281 | copy.disable = disable 282 | return copy 283 | } 284 | public func setDisableColor(_ color: Color) -> Self{ 285 | var copy = self 286 | copy.defaultDisableColor = color 287 | return copy 288 | } 289 | public func setDarkModeDisableColor(_ color: Color) -> Self{ 290 | var copy = self 291 | copy.darkModeDisableColor = color 292 | return copy 293 | } 294 | public func setError(errorText: Binding, error: Binding) -> Self { 295 | var copy = self 296 | copy.error = error 297 | copy.errorText = errorText 298 | return copy 299 | } 300 | public func setErrorTextColor(_ color: Color) -> Self{ 301 | var copy = self 302 | copy.defaultErrorTextColor = color 303 | return copy 304 | } 305 | public func setDarkModeErrorTextColor(_ color: Color) -> Self{ 306 | var copy = self 307 | copy.darkModeErrorTextColor = color 308 | return copy 309 | } 310 | public func setErrorFont(_ errorFont: Font) -> Self{ 311 | var copy = self 312 | copy.errorFont = errorFont 313 | return copy 314 | } 315 | public func setTrailingImage(_ image: Image, click: @escaping (()->Void)) -> Self{ 316 | var copy = self 317 | copy._trailingImage = State(initialValue: image) 318 | copy.trailingImageClick = click 319 | return copy 320 | } 321 | public func setSecureText(_ secure: Bool) -> Self{ 322 | var copy = self 323 | copy._secureText = State(initialValue: secure) 324 | if secure{ 325 | copy._trailingImage = State(initialValue: copy.secureTextImageClose) 326 | } 327 | copy.isSecureText = secure 328 | return copy 329 | } 330 | public func setSecureTextImages(open: Image, close: Image) -> Self{ 331 | var copy = self 332 | copy.secureTextImageOpen = open 333 | copy.secureTextImageClose = close 334 | copy._trailingImage = State(initialValue: copy.secureTextImageClose) 335 | return copy 336 | } 337 | public func setMaxCount(_ count: Int) -> Self{ 338 | var copy = self 339 | copy.maxCount = count 340 | return copy 341 | } 342 | public func setTruncateMode(_ mode: Text.TruncationMode) -> Self{ 343 | var copy = self 344 | copy.truncationMode = mode 345 | return copy 346 | } 347 | public func setBorderColor(_ color: Color) -> Self{ 348 | var copy = self 349 | copy.defaultBorderColor = color 350 | return copy 351 | } 352 | public func setDarkModeBorderColor(_ color: Color) -> Self{ 353 | var copy = self 354 | copy.darkModeBorderColor = color 355 | return copy 356 | } 357 | public func setTrailingImageForegroundColor(_ color: Color) -> Self{ 358 | var copy = self 359 | copy.defaultTrailingImageForegroundColor = color 360 | return copy 361 | } 362 | public func setDarkModeTrailingImageForegroundColor(_ color: Color) -> Self{ 363 | var copy = self 364 | copy.darkModeTrailingImageForegroundColor = color 365 | return copy 366 | } 367 | public func setFocusedBorderColorEnable(_ enable: Bool) -> Self{ 368 | var copy = self 369 | copy.focusedBorderColorEnable = enable 370 | return copy 371 | } 372 | public func setFocusedBorderColor(_ color: Color) -> Self{ 373 | var copy = self 374 | copy.defaultFocusedBorderColor = color 375 | return copy 376 | } 377 | public func setDarkModeFocusedBorderColor(_ color: Color) -> Self{ 378 | var copy = self 379 | copy.darkModeFocusedBorderColor = color 380 | return copy 381 | } 382 | public func setBorderWidth(_ width: CGFloat) -> Self{ 383 | var copy = self 384 | copy.borderWidth = width 385 | return copy 386 | } 387 | public func setBackgroundColor(_ color: Color) -> Self{ 388 | var copy = self 389 | copy.defaultBackgroundColor = color 390 | return copy 391 | } 392 | public func setDarkModeBackgroundColor(_ color: Color) -> Self{ 393 | var copy = self 394 | copy.darkModeBackgroundColor = color 395 | return copy 396 | } 397 | public func setCornerRadius(_ radius: CGFloat) -> Self{ 398 | var copy = self 399 | copy.cornerRadius = radius 400 | return copy 401 | } 402 | public func setBorderType(_ type: BorderType) -> Self{ 403 | var copy = self 404 | copy.borderType = type 405 | return copy 406 | } 407 | public func setDisableAutoCorrection(_ disable: Bool) -> Self{ 408 | var copy = self 409 | copy.disableAutoCorrection = disable 410 | return copy 411 | } 412 | public func setTextFieldHeight(_ height: CGFloat) -> Self{ 413 | var copy = self 414 | copy.textFieldHeight = height 415 | return copy 416 | } 417 | } 418 | 419 | @available(iOS 13.0, *) 420 | extension View { 421 | func placeholder( 422 | when shouldShow: Bool, 423 | alignment: Alignment = .leading, 424 | @ViewBuilder placeholder: () -> Content) -> some View { 425 | 426 | ZStack(alignment: alignment) { 427 | placeholder().opacity(shouldShow ? 1 : 0) 428 | self 429 | } 430 | } 431 | } 432 | -------------------------------------------------------------------------------- /Sources/CustomTextField/EGTextFieldConfig.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EGTextFieldConfig.swift 3 | // CustomEdittext 4 | // 5 | // Created by Esat Gözcü on 2023/04/03. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @available(iOS 13.0, *) 11 | public class EGTextFieldConfig{ 12 | public static var shared = EGTextFieldConfig() 13 | private init(){} 14 | 15 | //Text Color 16 | public var defaultTextColor : Color = .black 17 | public var darkModeTextColor : Color = .white 18 | //Title Color 19 | public var defaultTitleColor : Color = .black 20 | public var darkModeTitleColor : Color = .white 21 | //PlaceHolder Text Color 22 | public var defaultPlaceHolderTextColor : Color = .gray.opacity(0.8) 23 | public var darkModePlaceHolderTextColor : Color = .white.opacity(0.3) 24 | //Disable Color 25 | public var defaultDisableColor : Color = .gray.opacity(0.5) 26 | public var darkModeDisableColor : Color = .gray.opacity(0.3) 27 | //Background Color 28 | public var defaultBackgroundColor : Color = .white 29 | public var darkModeBackgroundColor : Color = .black 30 | //Error Text Color 31 | public var defaultErrorTextColor : Color = .red 32 | public var darkModeErrorTextColor : Color = .red 33 | //Border Color 34 | public var defaultBorderColor : Color = .gray 35 | public var darkModeBorderColor : Color = .white.opacity(0.7) 36 | //Trailing Image Color 37 | public var defaultTrailingImageForegroundColor : Color = .black 38 | public var darkModeTrailingImageForegroundColor : Color = .white 39 | //Focused Border Color 40 | public var focusedBorderColorEnable: Bool = false 41 | public var defaultFocusedBorderColor : Color = .black 42 | public var darkModeFocusedBorderColor : Color = .white 43 | //Font 44 | public var textFont : Font = .system(size: 17) 45 | public var titleFont : Font = .callout 46 | public var errorFont : Font = .footnote 47 | public var placeHolderFont : Font = .subheadline 48 | //Default 49 | public var borderWidth : CGFloat = 1.0 50 | public var cornerRadius : CGFloat = 5.0 51 | public var borderType: BorderType = .square 52 | public var disableAutoCorrection: Bool = false 53 | public var textFieldHeight : CGFloat = 45 54 | } 55 | 56 | public enum BorderType { 57 | case square 58 | case line 59 | } 60 | --------------------------------------------------------------------------------