AuthTextField
AuthTextField allows you to easily create and validate animated textfields on the authentication screens for your applications.
Contents
Requirements
- iOS 12+
- Swift 5+
- Xcode 10+
Installation
AuthTextField is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'AuthTextField'
Usage
Quick Start
Programmatically usage
import UIKit
import AuthTextField
class ViewController: UIViewController {
let nameTextfield = AuthField()
override func viewDidLoad() {
super.viewDidLoad()
nameTextfield.inputType = .name
self.view.addSubview(nameTextfield)
nameTextfield.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
nameTextfield.leadingAnchor.constraint(equalTo: self.view.leadingAnchor,constant: 20),
nameTextfield.trailingAnchor.constraint(equalTo: self.view.trailingAnchor,constant: -20),
nameTextfield.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: 20),
nameTextfield.heightAnchor.constraint(equalToConstant: 50)
])
}
}
Storyboard Usage
Firstly insert UIView object in your view than enter in identitiy inspector and change inside Custom Class -> Class to AuthField. Connect your UIView to ViewController.swift file.
import UIKit
import AuthTextField
class ViewController: UIViewController {
@IBOutlet weak var nameTextField: AuthField!
override func viewDidLoad() {
super.viewDidLoad()
nameTextField.inputType = .name
}
}
Detail Usage
Validation
You can check your textfield does give your requirements and it return you true false result. If result is fault trigger animation.
import UIKit
import AuthTextField
class ViewController: UIViewController {
@IBOutlet weak var nameTextField: AuthField!
override func viewDidLoad() {
super.viewDidLoad()
nameTextField.inputType = .name
nameTextField.checkField()
}
}
Default Properties
public var inputType: InputTypeSelection?
public var isOptional = false
public var animationType: AnimationTypeSelection = .shake
public var noticeBorderColor: UIColor = .red
public var textColor: UIColor = .lightGray
public var inputColor: UIColor = .lightGray
public var labelFontSmall: UIFont = .systemFont(ofSize: 12)
public var labelFontLarge: UIFont = .boldSystemFont(ofSize: 15)
public var minCharacter: Int = 3
public var isDeleteButtonAvaliable = false
public func setFourCornerBorder() // Preset 4 corner border style
public func setUnderLineBorder() // Just sets underline border style
public func setLabelText(String) // If you are using localization on your app's then you have to use this func
Example usage -> emailInput.setLabelText("AuthViewController.RegisterCollectionViewCell.emailTitle".localized())
Delete Button
Add your textfield a delete button and set buttons color.
import UIKit
import AuthTextField
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
passwordTextField.inputType = .password
passwordTextField.isDeleteButtonAvaliable = false
passwordTextField.deleteButtonColor = .blue
}
}
Animations
For animation type we have 3 types. Shake, pulse and flash. If you don't want any animation you have to select .animationType = .none
import UIKit
import AuthTextField
class ViewController: UIViewController {
@IBOutlet weak var firstTextField: AuthField!
@IBOutlet weak var secondTextField: AuthField!
@IBOutlet weak var thirdTextField: AuthField!
override func viewDidLoad() {
super.viewDidLoad()
firstTextField.inputType = .name
secondTextField.inputType = .name
thirdTextField.inputType = .name
//Setting animation Preset animationType = .shake
firstTextField.animationType = .shake
secondTextField.animationType = .pulse
thirdTextField.animationType = .flash
}
@IBAction func validateButtonPressed(_ sender: Any) {
firstTextField.checkField()
secondTextField.checkField()
thirdTextField.checkField()
}
}
Password
import UIKit
import AuthTextField
class ViewController: UIViewController {
@IBOutlet weak var passwordTextField: AuthField!
override func viewDidLoad() {
super.viewDidLoad()
passwordTextField.inputType = .password
}
@IBAction func validateButtonPressed(_ sender: Any) {
passwordTextField.checkField()
}
}
Email Validation
If input type selected e-mail when you gonna validate textfield it will be automatically check e-mail format.
class ViewController: UIViewController {
import UIKit
import AuthTextField
class ViewController: UIViewController {
@IBOutlet weak var emailTextField: AuthField!
override func viewDidLoad() {
super.viewDidLoad()
emailTextField.inputType = .email
}
@IBAction func validateButtonPressed(_ sender: Any) {
emailTextField.checkField()
}
}
Create Custom AuthField
import UIKit
import AuthTextField
class ViewController: UIViewController {
@IBOutlet weak var customFirstTextField: AuthField!
@IBOutlet weak var customSecondTextField: AuthField!
override func viewDidLoad() {
super.viewDidLoad()
customFirstTextField.inputType = .custom
customFirstTextField.setCustomAuthField(isOptional: true, animationType: .flash, noticeColor: .red, textColor: .lightGray, textfieldInputColor: .purple, textFieldInputFont: .systemFont(ofSize: 15), titleLabelSmallSizeFont: .systemFont(ofSize: 12), titleLabelLargeSizeFont: .boldSystemFont(ofSize: 15), placeHolderText: "Custom First Optional", requiredMinCharacter: 1)
customSecondTextField.inputType = .custom
customTextField.setCustomAuthField(isOptional: true, animationType: .flash, noticeColor: .blue, textColor: .orange, textfieldInputColor: .orange, textFieldInputFont: .boldSystemFont(ofSize: 15), titleLabelSmallSizeFont: .systemFont(ofSize: 12), titleLabelLargeSizeFont: .boldSystemFont(ofSize: 15), placeHolderText: "Custom", requiredMinCharacter: 5, isDeleteButtonAvaliable: false, deleteButtonColor: .blue)
}
@IBAction func validateButtonPressed(_ sender: Any) {
customFirstTextField.checkField()
customSecondTextField.checkField()
}
}
Author
ferhanakkan, ferhanakkan@gmail.com
License
AuthTextField is available under the MIT license. See the LICENSE file for more info.