Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
# FloatingLabelTextFieldSwiftUI
2
 
3
[![CI Status](https://img.shields.io/travis/kishanraja/FloatingLabelTextFieldSwiftUI.svg?style=flat)](https://travis-ci.org/kishanraja/FloatingLabelTextFieldSwiftUI)
4
[![Version](https://img.shields.io/cocoapods/v/FloatingLabelTextFieldSwiftUI.svg?style=flat)](https://cocoapods.org/pods/FloatingLabelTextFieldSwiftUI)
5
[![License](https://img.shields.io/cocoapods/l/FloatingLabelTextFieldSwiftUI.svg?style=flat)](https://cocoapods.org/pods/FloatingLabelTextFieldSwiftUI)
6
[![Platform](https://img.shields.io/cocoapods/p/FloatingLabelTextFieldSwiftUI.svg?style=flat)](https://cocoapods.org/pods/FloatingLabelTextFieldSwiftUI)
7
 
8
 
9
FloatingLabelTextFieldSwiftUI is a small and lightweight SwiftUI framework written in completely swiftUI (not using UIViewRepresentable) that allows to create beautiful and customisable floating label textfield! This library support RTL text (eg. Arabic) and easy to add left view and right view to your text field and customizable.
10
 
11
<p float="left">
12
    <img src="https://github.com/kishanraja/FloatingLabelTextFieldSwiftUI/blob/master/Graphics/FloatingLabelTextFieldSwiftUI.gif" width="350" height="623" >
13
 
14
</p>
15
 
16
If you like the project, please do not forget to `star ★` this repository and follow me on GitHub.
17
 
18
 
19
## 📦 Requirements
20
 
21
- iOS 13.0+
22
- Xcode 11.2+
23
- Swift 5.0
24
 
25
## 💻 Usage
26
 
27
To start using the component add it to your project using CocoaPods or Swift Package. First of all import FloatingLabelTextFieldSwiftUI
28
 
29
```swift
30
import FloatingLabelTextFieldSwiftUI
31
```
32
 
33
<p float="left">
34
    <img src="https://github.com/kishanraja/FloatingLabelTextFieldSwiftUI/blob/master/Graphics/normal_text_field.gif">
35
 
36
</p>
37
 
38
```swift
39
struct ContentView: View {
40
 
41
    @State private var firstName: String = ""
42
 
43
    var body: some View {
44
 
45
        FloatingLabelTextField($firstName, placeholder: "First Name", editingChanged: { (isChanged) in
46
 
47
        }) {
48
 
49
        }.frame(height: 70)
50
    }
51
}
52
```
53
 
54
### FloatingLabelTextFieldStyle and Colors:
55
 
56
You can customize the colors of the textfield by using FloatingLabelTextFieldStyle property or create your own style and set a few properties.
57
 
58
#### Property
59
 
60
```swift
61
struct ContentView: View {
62
 
63
    @State private var firstName: String = ""
64
 
65
    var body: some View {
66
 
67
        FloatingLabelTextField($firstName, placeholder: "First Name", editingChanged: { (isChanged) in
68
 
69
        }) {
70
 
71
        }
72
        .titleColor(.green)
73
        .selectedLineColor(.blue)
74
        .selectedTextColor(.blue)
75
        .selectedTitleColor(.blue)
76
        .frame(height: 70)
77
    }
78
}
79
```
80
#### FloatingLabelTextFieldStyle
81
 
82
Just two step for create and add style to FloatingLabelTextField.
83
 
84
1. Create your own theme style. Set property as per your theme.
85
 
86
```swift
87
struct ThemeTextFieldStyle: FloatingLabelTextFieldStyle {
88
    func body(content: FloatingLabelTextField) -> FloatingLabelTextField {
89
        content
90
            .spaceBetweenTitleText(15) // Sets the space between title and text.
91
            .textAlignment(.leading) // Sets the alignment for text.
92
            .lineHeight(1) // Sets the line height.
93
            .selectedLineHeight(1.5) // Sets the selected line height.
94
            .lineColor(.gray) // Sets the line color.
95
            .selectedLineColor(.blue) // Sets the selected line color.
96
            .titleColor(.gray) // Sets the title color.
97
            .selectedTitleColor(.blue) // Sets the selected title color.
98
            .titleFont(.system(size: 12)) // Sets the title font.
99
            .textColor(.black) // Sets the text color.
100
            .selectedTextColor(.blue) // Sets the selected text color.
101
            .textFont(.system(size: 15)) // Sets the text font.
102
            .placeholderColor(.gray) // Sets the placeholder color.
103
            .placeholderFont(.system(size: 15)) // Sets the placeholder font.
104
            .errorColor(.red) // Sets the error color.
105
            .addDisableEditingAction([.paste]) // Disable text field editing action. Like cut, copy, past, all etc.
106
            .enablePlaceholderOnFocus(true) // Enable the placeholder label when the textfield is focused.
107
            .allowsHitTesting(true) // Whether this view participates in hit test operations.
108
            .disabled(false) // Whether users can interact with this.
109
    }
110
}
111
```
112
 
113
2. Add style to FloatingLabelTextField.
114
 
115
```swift
116
struct ContentView: View {
117
 
118
    @State private var firstName: String = ""
119
 
120
    var body: some View {
121
        FloatingLabelTextField($firstName, placeholder: "First Name", editingChanged: { (isChanged) in
122
 
123
        }) {
124
 
125
        }
126
        .floatingStyle(ThemeTextFieldStyle())
127
        .frame(height: 70)
128
    }
129
}
130
```
131
 
132
### Secure Text Entry
133
To enable Secure Text Entry use .isSecureTextEntry(true) property.
134
 
135
<p float="left">
136
    <img src="https://github.com/kishanraja/FloatingLabelTextFieldSwiftUI/blob/master/Graphics/secure_text_field.gif">
137
 
138
</p>
139
 
140
```swift
141
struct ContentView: View {
142
 
143
    @State private var password: String = ""
144
 
145
    var body: some View {
146
        HStack(spacing: 20) {
147
            FloatingLabelTextField($password, placeholder: "Password", editingChanged: { (isChanged) in
148
 
149
            }) {
150
 
151
            }
152
            .isSecureTextEntry(true)
153
            .frame(height: 70)
154
        }
155
    }
156
}
157
```
158
 
159
### Left - Right View
160
Yes, you can easily add your own views, buttons or image to left view or right view of the FloatingLabelTextField.
161
 
162
<p float="left">
163
    <img src="https://github.com/kishanraja/FloatingLabelTextFieldSwiftUI/blob/master/Graphics/left-right-view.gif">
164
 
165
</p>
166
 
167
```swift
168
struct ContentView: View {
169
 
170
    @State private var password: String = ""
171
    @State private var isPasswordShow: Bool = false
172
 
173
    var body: some View {
174
        FloatingLabelTextField($password, placeholder: "Password", editingChanged: { (isChanged) in
175
 
176
        }) {
177
 
178
        }
179
        .isSecureTextEntry(!self.isPasswordShow)
180
            .leftView({ // Add left view.
181
                Image("password")
182
            })
183
            .rightView({ // Add right view.
184
                Button(action: {
185
                    withAnimation {
186
                        self.isPasswordShow.toggle()
187
                    }
188
 
189
                }) {
190
                    Image(self.isPasswordShow ? "eye_close" : "eye_show")
191
                }
192
            })
193
            .frame(height: 70)
194
            .padding()
195
    }
196
}
197
```
198
 
199
### Error Message & Validation
200
 
201
FloatingLableTextFieldSwiftUI supports displaying an error and add text field validations. This can be helpfull for adding validation on your form text field. To enable isShowError property to true and pass text field validations array to text field with message according condition. You can also add validation checker variable to check is text field is valid or not on submit button action.
202
 
203
FloatingLabelTextFieldSwiftUI also have some inbuilt validation regex checker fields like email, password, name, number.. etc.
204
 
205
Here is some example
206
 
207
1. Email Validation
208
<p float="left">
209
    <img src="https://github.com/kishanraja/FloatingLabelTextFieldSwiftUI/blob/master/Graphics/email_validation.gif">
210
 
211
</p>
212
 
213
```swift
214
struct ContentView: View {
215
 
216
    @State private var email: String = ""
217
    @State private var isValidEmail: Bool = false
218
 
219
    var body: some View {
220
        VStack {
221
            FloatingLabelTextField($email, validtionChecker: $isValidEmail, placeholder: "Email", editingChanged: { (isChanged) in
222
 
223
            }) {
224
 
225
            }
226
            .addValidation(.init(condition: email.isValid(.email), errorMessage: "Invalid Email")) /// Sets the validation condition.
227
                .isShowError(true) /// Sets the is show error message.
228
                .errorColor(.red) /// Sets the error color.
229
                .keyboardType(.emailAddress)
230
                .frame(height: 70)
231
                .padding()
232
 
233
            Button(action: {
234
                self.endEditing(true)
235
 
236
                if self.isValidEmail {
237
                    print("Valid Email")
238
 
239
                } else {
240
                    print("Invalid Email")
241
                }
242
 
243
            }) {
244
                Text("Create")
245
            }
246
        }
247
    }
248
}
249
```
250
 
251
 
252
2. Name Validation
253
<p float="left">
254
    <img src="https://github.com/kishanraja/FloatingLabelTextFieldSwiftUI/blob/master/Graphics/name_validation.gif">
255
 
256
</p>
257
 
258
```swift
259
struct ContentView: View {
260
 
261
    @State private var lastName: String = ""
262
 
263
    var body: some View {
264
        FloatingLabelTextField($lastName, placeholder: "Last Name", editingChanged: { (isChanged) in
265
 
266
        }) {
267
 
268
        }
269
        .isShowError(true) /// Sets the is show error message.
270
        .addValidations([.init(condition: lastName.isValid(.alphabet), errorMessage: "Invalid Name"),
271
                         .init(condition: lastName.count >= 2, errorMessage: "Minimum two character long")
272
        ]) /// Sets the validation conditions.
273
            .floatingStyle(ThemeTextFieldStyle2())
274
            .frame(height: 70)
275
    }
276
}
277
```
278
 
279
 
280
## 🐾 Examples
281
 
282
To run the example project, clone the repo, and run `pod install` from the Example directory first.
283
 
284
## 💾 Installation
285
 
286
### CocoaPods:
287
 
288
FloatingLabelTextFieldSwiftUI is available through [CocoaPods](https://cocoapods.org). To install
289
it, simply add the following line to your Podfile:
290
 
291
```ruby
292
pod 'FloatingLabelTextFieldSwiftUI'
293
```
294
 
295
### Swift Package Manager
296
 
297
The [Swift Package Manager](https://swift.org/package-manager/) is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
298
 
299
To integrate `FloatingLabelTextFieldSwiftUI` into your Xcode project using Xcode 11+, specify it in `File > Swift Packages > Add`:
300
 
301
```ogdl
302
https://github.com/kishanraja/FloatingLabelTextFieldSwiftUI.git
303
```
304
 
305
### Manual
306
 
307
You can download the latest files from our [Releases page](https://github.com/kishanraja/FloatingLabelTextFieldSwiftUI/releases). After doing so, copy the files in the `Sources` folder to your project.
308
 
309
 
310
## 🙋🏻‍♂️ Author
311
 
312
kishanraja, rajakishanrk1996@gmail.com
313
 
314
## 💰 Contribution
315
 
316
Feel free to fork the project and send me a pull-request!
317
 
318
## 📝 Feedback
319
Please file an [Issue](https://github.com/kishanraja/FloatingLabelTextFieldSwiftUI/issues).
320
 
321
## 📜 License
322
 
323
FloatingLabelTextFieldSwiftUI is available under the MIT license. See the LICENSE file for more info.