All Projects → kishanraja → Floatinglabeltextfieldswiftui

kishanraja / Floatinglabeltextfieldswiftui

Licence: mit
Floating Label TextField for SwiftUI. FloatingLabelTextFieldSwiftUI

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Floatinglabeltextfieldswiftui

Tweetextfield
Lightweight set of text fields with nice animation and functionality. 🚀 Inspired by https://uimovement.com/ui/2524/input-field-help/
Stars: ✭ 421 (+228.91%)
Mutual labels:  cocoapods, interface-builder, textfield
Skyfloatinglabeltextfield
A beautiful and flexible text field control implementation of "Float Label Pattern". Written in Swift.
Stars: ✭ 3,907 (+2952.34%)
Mutual labels:  cocoapods, interface-builder, textfield
Simplecheckbox
A simple Checkbox
Stars: ✭ 253 (+97.66%)
Mutual labels:  cocoapods, interface-builder
Passwordtextfield
A custom TextField with a switchable icon which shows or hides the password and enforce good password policies
Stars: ✭ 281 (+119.53%)
Mutual labels:  cocoapods, textfield
Uitextfield Navigation
🏄‍♂️ UITextField-Navigation makes it easier to navigate between UITextFields and UITextViews
Stars: ✭ 436 (+240.63%)
Mutual labels:  cocoapods, interface-builder
Switch
💊 An iOS switch control implemented in Swift with full Interface Builder support
Stars: ✭ 132 (+3.13%)
Mutual labels:  cocoapods, interface-builder
Underlinetextfield
Simple UITextfield Subclass with state
Stars: ✭ 156 (+21.88%)
Mutual labels:  cocoapods, textfield
Cminputview
💪之前代码是基于UITextView进行的封装,侵入性较强,不方便使用,现使用Category重构代码,支持Cocoapods
Stars: ✭ 149 (+16.41%)
Mutual labels:  cocoapods, textfield
Ttsegmentedcontrol
An elegant, animated and customizable segmented control for iOS created by Tapptitude
Stars: ✭ 471 (+267.97%)
Mutual labels:  cocoapods, interface-builder
Yalfield
Custom Field component with validation for creating easier form-like UI from interface builder.
Stars: ✭ 476 (+271.88%)
Mutual labels:  cocoapods, interface-builder
Forceblur
ForceBlur Animation for iOS Messaging Apps
Stars: ✭ 666 (+420.31%)
Mutual labels:  cocoapods, interface-builder
Everlayout
Reusable, downloadable, up-datable iOS layouts
Stars: ✭ 103 (-19.53%)
Mutual labels:  cocoapods, interface-builder
Iblocalizable
Localize your views directly in Interface Builder with IBLocalizable
Stars: ✭ 463 (+261.72%)
Mutual labels:  cocoapods, interface-builder
Taniwhatextfield
My first cocoapod framework
Stars: ✭ 26 (-79.69%)
Mutual labels:  cocoapods, textfield
Tkkeyboardcontrol
TKKeyboardControl adds keyboard awareness and scrolling dismissal (like iMessages app) to any view with only 1 line of code for Swift.
Stars: ✭ 110 (-14.06%)
Mutual labels:  cocoapods, textfield
Sqift
Powerful Swift wrapper for SQLite
Stars: ✭ 119 (-7.03%)
Mutual labels:  cocoapods
Tinynetworking
🌩 Simple HTTP network abstraction layer written in Swift
Stars: ✭ 122 (-4.69%)
Mutual labels:  cocoapods
Dddkit
360 video player for iOS written in swift - a subset of SceneKit that works
Stars: ✭ 118 (-7.81%)
Mutual labels:  cocoapods
Swifty360player
iOS 360-degree video player streaming from an AVPlayer.
Stars: ✭ 118 (-7.81%)
Mutual labels:  cocoapods
Croc
Swift emoji string parsing library
Stars: ✭ 124 (-3.12%)
Mutual labels:  cocoapods

FloatingLabelTextFieldSwiftUI

CI Status Version License Platform

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.

If you like the project, please do not forget to star ★ this repository and follow me on GitHub.

📦 Requirements

  • iOS 13.0+
  • Xcode 11.2+
  • Swift 5.0

💻 Usage

To start using the component add it to your project using CocoaPods or Swift Package. First of all import FloatingLabelTextFieldSwiftUI

import FloatingLabelTextFieldSwiftUI

struct ContentView: View {
    
    @State private var firstName: String = ""
    
    var body: some View {
        
        FloatingLabelTextField($firstName, placeholder: "First Name", editingChanged: { (isChanged) in
            
        }) {
            
        }.frame(height: 70)
    }
}

FloatingLabelTextFieldStyle and Colors:

You can customize the colors of the textfield by using FloatingLabelTextFieldStyle property or create your own style and set a few properties.

Property

struct ContentView: View {
    
    @State private var firstName: String = ""
    
    var body: some View {
        
        FloatingLabelTextField($firstName, placeholder: "First Name", editingChanged: { (isChanged) in
            
        }) {
            
        }
        .titleColor(.green)
        .selectedLineColor(.blue)
        .selectedTextColor(.blue)
        .selectedTitleColor(.blue)
        .frame(height: 70)
    }
}

FloatingLabelTextFieldStyle

Just two step for create and add style to FloatingLabelTextField.

  1. Create your own theme style. Set property as per your theme.
struct ThemeTextFieldStyle: FloatingLabelTextFieldStyle {
    func body(content: FloatingLabelTextField) -> FloatingLabelTextField {
        content
            .spaceBetweenTitleText(15) // Sets the space between title and text.
            .textAlignment(.leading) // Sets the alignment for text.
            .lineHeight(1) // Sets the line height.
            .selectedLineHeight(1.5) // Sets the selected line height.
            .lineColor(.gray) // Sets the line color.
            .selectedLineColor(.blue) // Sets the selected line color.
            .titleColor(.gray) // Sets the title color.
            .selectedTitleColor(.blue) // Sets the selected title color.
            .titleFont(.system(size: 12)) // Sets the title font.
            .textColor(.black) // Sets the text color.
            .selectedTextColor(.blue) // Sets the selected text color.
            .textFont(.system(size: 15)) // Sets the text font.
            .placeholderColor(.gray) // Sets the placeholder color.
            .placeholderFont(.system(size: 15)) // Sets the placeholder font.
            .errorColor(.red) /// Sets the error color.
            .addDisableEditingAction([.paste]) /// Disable text field editing action. Like cut, copy, past, all etc.
    }
}
  1. Add style to FloatingLabelTextField.
struct ContentView: View {
    
    @State private var firstName: String = ""
    
    var body: some View {
        FloatingLabelTextField($firstName, placeholder: "First Name", editingChanged: { (isChanged) in
            
        }) {
            
        }
        .floatingStyle(ThemeTextFieldStyle())
        .frame(height: 70)
    }
}

Secure Text Entry

To enable Secure Text Entry use .isSecureTextEntry(true) property.

struct ContentView: View {
    
    @State private var password: String = ""
    
    var body: some View {
        HStack(spacing: 20) {
            FloatingLabelTextField($password, placeholder: "Password", editingChanged: { (isChanged) in
                
            }) {
                
            }
            .isSecureTextEntry(true)
            .frame(height: 70)
        }
    }
}

Left - Right View

Yes, you can easily add your own views, buttons or image to left view or right view of the FloatingLabelTextField.

struct ContentView: View {
    
    @State private var password: String = ""
    @State private var isPasswordShow: Bool = false
    
    var body: some View {
        FloatingLabelTextField($password, placeholder: "Password", editingChanged: { (isChanged) in
            
        }) {
            
        }
        .isSecureTextEntry(!self.isPasswordShow)
            .leftView({ // Add left view.
                Image("password")
            })
            .rightView({ // Add right view.
                Button(action: {
                    withAnimation {
                        self.isPasswordShow.toggle()
                    }
                    
                }) {
                    Image(self.isPasswordShow ? "eye_close" : "eye_show")
                }
            })
            .frame(height: 70)
            .padding()
    }
}

Error Message & Validation

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.

FloatingLabelTextFieldSwiftUI also have some inbuilt validation regex checker fields like email, password, name, number.. etc.

Here is some example

  1. Email Validation

struct ContentView: View {
    
    @State private var email: String = ""
    @State private var isValidEmail: Bool = false
    
    var body: some View {
        VStack {
            FloatingLabelTextField($email, validtionChecker: $isValidEmail, placeholder: "Email", editingChanged: { (isChanged) in
                
            }) {
                
            }
            .addValidation(.init(condition: email.isValid(.email), errorMessage: "Invalid Email")) /// Sets the validation condition.
                .isShowError(true) /// Sets the is show error message.
                .errorColor(.red) /// Sets the error color.
                .keyboardType(.emailAddress)
                .frame(height: 70)
                .padding()
            
            Button(action: {
                self.endEditing(true)
                
                if self.isValidEmail {
                    print("Valid Email")
                    
                } else {
                    print("Invalid Email")
                }
                
            }) {
                Text("Create")
            }
        }
    }
}
  1. Name Validation

struct ContentView: View {
    
    @State private var lastName: String = ""
    
    var body: some View {
        FloatingLabelTextField($lastName, placeholder: "Last Name", editingChanged: { (isChanged) in
            
        }) {
            
        }
        .isShowError(true) /// Sets the is show error message.
        .addValidations([.init(condition: lastName.isValid(.alphabet), errorMessage: "Invalid Name"),
                         .init(condition: lastName.count >= 2, errorMessage: "Minimum two character long")
        ]) /// Sets the validation conditions.
            .floatingStyle(ThemeTextFieldStyle2())
            .frame(height: 70)
    }
}

🐾 Examples

To run the example project, clone the repo, and run pod install from the Example directory first.

💾 Installation

CocoaPods:

FloatingLabelTextFieldSwiftUI is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'FloatingLabelTextFieldSwiftUI'

Swift Package Manager

The Swift 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.

To integrate FloatingLabelTextFieldSwiftUI into your Xcode project using Xcode 11+, specify it in File > Swift Packages > Add:

https://github.com/kishanraja/FloatingLabelTextFieldSwiftUI.git

Manual

You can download the latest files from our Releases page. After doing so, copy the files in the Sources folder to your project.

🙋🏻‍♂️ Author

kishanraja, [email protected]

💰 Contribution

Feel free to fork the project and send me a pull-request!

📝 Feedback

Please file an Issue.

📜 License

FloatingLabelTextFieldSwiftUI is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].