SwiftUI-Custom-TextField

所属分类:前端开发
开发工具:Swift
文件大小:10KB
下载次数:0
上传日期:2023-05-24 07:13:03
上 传 者sh-1993
说明:  自定义TextField组件SwiftUI。它基于编程UI构建,并且完全可定制。
(Custom TextField component SwiftUI. It is built upon programmatic UI and fully customizable.)

文件列表:
.swiftpm (0, 2023-05-24)
.swiftpm\xcode (0, 2023-05-24)
.swiftpm\xcode\package.xcworkspace (0, 2023-05-24)
.swiftpm\xcode\package.xcworkspace\xcshareddata (0, 2023-05-24)
.swiftpm\xcode\package.xcworkspace\xcshareddata\IDEWorkspaceChecks.plist (238, 2023-05-24)
LICENSE (1069, 2023-05-24)
Package.swift (1053, 2023-05-24)
Sources (0, 2023-05-24)
Sources\CustomTextField (0, 2023-05-24)
Sources\CustomTextField\EGTextField.swift (15897, 2023-05-24)
Sources\CustomTextField\EGTextFieldConfig.swift (2023, 2023-05-24)
Tests (0, 2023-05-24)
Tests\CustomTextFieldTests (0, 2023-05-24)
Tests\CustomTextFieldTests\CustomTextFieldTests.swift (366, 2023-05-24)

Logo

Swift 5.6 SwiftUI MIT License

# SwiftUI Custom TextField This repository developed with only swiftUI, there is no UIViewRepresentable. #### Requirements - iOS 13.0+ - Xcode 13+ - Swift 5+ #### Swift Package Manager CustomTextfield is available through [Swift Package Manager](https://swift.org/package-manager/). Add CustomTextField as a dependency to your `Package.swift`: ```Swift .package(url: "https://github.com/esatgozcu/SwiftUI-Custom-TextField", from: "main") ``` ## Customize config You can set your [config](Sources/CustomTextField/EGTextFieldConfig.swift) properties in @main so you don't need to set every time. ```Swift @main struct ExampleApp: App { init() { let shared = EGTextFieldConfig.shared shared.defaultTextColor = .black shared.darkModeTextColor = .white shared.defaultTitleColor = .black shared.darkModeTitleColor = .white shared.titleFont = .body shared.borderType = .line ... } var body: some Scene { WindowGroup { ContentView() } } } ``` ## Dark Mode 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. #### Default initialize ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) .setTitleText("Title") ``` #### Light Light Mode #### Dark Dark Mode ## Examples #### Default ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) ``` Default #### Line Border ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) .setBorderType(.line) ``` Line Border #### Title ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) .setTitleText("Name") .setTitleColor(.blue) .setTitleFont(.body) ``` Title #### PlaceHolder ```swift @State var text = "" EGTextField(text: $text) .setPlaceHolderText("Enter a name") ``` PlaceHolder Also if you want you can change placeholder color ```swift @State var text = "" EGTextField(text: $text) .setPlaceHolderText("Enter a name") .setPlaceHolderTextColor(Color.gray) ``` #### Disable ```swift @State var text = "Esat Gozcu" @State var disable = true EGTextField(text: $text) .setDisable($disable) .setDisableColor(Color.gray.opacity(0.2)) ``` Disable #### Bottom Error ```swift @State var text = "Esat Gozcu" @State var error = true @State var errorText = "Your name is not matched" EGTextField(text: $text) .setError(errorText: $errorText, error: $error) ``` Bottom Error #### Trailing Image ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) .setTrailingImage(Image(systemName: "qrcode"), click: { print("qr image tapped") }) ``` Trailing Image You can also set image foreground color. ```swift EGTextField(text: $text) .setTrailingImageForegroundColor(.black) .setDarkModeTrailingImageForegroundColor(.white) ``` 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. #### Secure Text ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) .setSecureText(true) ``` Secure Text Close Secure Text Open Secure text images can be changed ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) .setSecureText(true) .setSecureTextImages(open : Image(systemName: "eye.fill"), close: Image(systemName: "eye.slash.fill")) ``` #### Max Count ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) .setMaxCount(8) ``` Max Count #### Truncation Mode ```swift @State var text = "esat1feyk23mqjyefycrfk862x78cyk2sy9l0t8rt6c" EGTextField(text: $text) .setTruncateMode(.middle) ``` Truncation Mode #### Border Color and Width ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) .setBorderColor(.orange) .setBorderWidth(1.0) ``` Border Color #### Text Color ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) .setTextColor(.blue) ``` Text Color #### Background Color ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) .setBackgroundColor(Color.black) .setTextColor(Color.white) ``` Background Color #### Corner Radius ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) .setCornerRadius(20.0) ``` Corner Radius #### Disable Auto Correction ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) .setDisableAutoCorrection(true) ``` #### Set Height ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) .setTextFieldHeight(45) ``` #### Focused Border Color ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) .setFocusedBorderColorEnable(true) ``` Normal Focused If you want you can change colors. ```swift @State var text = "Esat Gozcu" EGTextField(text: $text) .setFocusedBorderColorEnable(true) .setFocusedBorderColor(.black) .setDarkModeFocusedBorderColor(.white) ``` Warning: This feauture is not working on secureField.

近期下载者

相关文件


收藏者