As iOS developers, most often we develop apps that have one or more forms prompting the user to enter his/her email address, date of birth, gender, phone number, etc. In such cases, we typically use UITextField and customize a few properties to launch different view pickers/keyboards.
Since this is very common in iOS apps, we have created a UITextField wrapper class called AITextField that allows us to use a single textfield to present different pickers/keyboards as required.
The wrapper saves us precious time previously spent developing the most common UI behavior and allows us to focus on solving new problems instead.
Adding AITextField to your project is simple – just follow the steps below.
a) Using Through Interface Builder
3. Create an IBOutlet and use it in your class.
b) Using Programmatically.
Use the init with frame function and add the field to your view.
let myTextField = AITextField.init(frame: myFrame)
For Date Picker
dateOfBirthTextField.textFieldType = .DatePickerTextField
For Phone Pad
phoneNumberTextField.textFieldType = .PhoneNumberTextField
For Text Picker
genderTextField.pickerViewArray = [“Female”, “Male", “Others”]
genderTextField.textFieldType = .TextPickerTextField
You can also use this AITextField as a general UITextField.
Adding Left and Right Views
myTextField.setLeftGap(width: 10, placeHolderImage: UIImage(named: “settings”)!)
myTextField.setRightGap(width: 10, placeHolderImage: UIImage(named: "copy")!)
Styling Input View
We can add a separator at the bottom of the text field using:
myTextField.createSeparator(borderColor: .darkGray, xpos: 10)
You can find the source code and AITextField class here.
Please drop a