A Simple And Easy Text Field Control Written In Swift

img source: venturebeat.com

I love Apple’s Swift programming language and how easy it is to create code in this language.

However, not all applications are created equal.

You probably don’t need an app that can do something like this:

Today, I’d like to present you a simple and easy text field control written in Swift, which is based on the concept of the Canvas TextField control.

If we have an interface that allows a user to enter text into a text field, we can use the control within our app.


A nice OTP textbox library for iOS, written in Swift with full accessibility user interface customization. AEOTPTextField is a simple and convenient text field control written in Swift.

  • It can be implemented in a storyboard without a single line of code.
  • x] Very customizable without having to write tons of custom code.
  • x] Support for portrait and landscape view.

Check out a sample project to see it in action!

Provisional sample



  • x] Xcode 11.
  • x] Swift 5.
  • x] iOS 10 or later.



CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command: $ gem install cocoapods To include AEOTPTextField in your Xcode project with CocoaPods, specify it in your podfile: Source ‘https://github.com/CocoaPods/Specs.git’ Platform :ios, ‘10.0’ use_frameworks ! pod AEOTextField Then run the following command: $ pod install


The integration of AEOTPTextField with Carthage will be available soon.

Swift Package Manager

AEOTPTextField integration with the Swift package manager will be available soon.


Code-free implementation of storyboard

  1. Add a UITextField to your ViewController. Set the custom field class UITextField as AEOTPTextField in the Identity Inspector. Set the module to AEOTPTextField (skip this step if you added AEOTPTextField to your project manually).


  1. Bring the ultimate UITextField to your ViewController.



1 : import AEOTPTextField Set otpDelegate and configure AEOTPTextField under viewDidLoad(), do something like this: override func viewDidLoad() { super.viewDidLoad() otpTextField.otpDelegate = self otpTextField.configure() } To configure an AEOTPTextField with a user-defined number of slots, do approximately the following: override func viewDidLoad() { super.viewDidLoad() otpTextField.otpDelegate = self otpTextField.configure(with : 4) } Next configure the AEOTPTextFieldDelegate method. Add this extension to your ViewController, do something like this: ViewController extension: AEOTPTextFieldDelegate { func didUserFinishEnter(the code : String) { print(code) } } You have.


AEOTPTextField AEOTPTextField supports the following: // default character to be placed in text field locations public var otpDefaultCharacter = // default background color in text field locations before character entry public var otpBackgroundColor : UIColor = UIColor(red: 0.949, green: 0.949, blue: 0.949, alpha: 1) // Default background color for text field locations after character input public var otpFilledBackgroundColor: UIColor = UIColor(red: 0.949, green: 0.949, blue: 0.949, alpha: 1) // Corner radius of the standard text field slots public var otpCornerRaduis: CGFloat = 10 // default border color of text field locations before a character is entered public var otpDefaultBorderColor : UIColor = .clear // The border color of the text field slots after the character has been entered public var otpFilledBorderColor : UIColor = .darkGray // default border width of the text field slots before the character is entered public var otpDefaultBorderWidth : CGFloat = 0 // Text field border width after character input public var otpFilledBorderWidth : CGFloat = 1 // default text color public var otpTextColor : UIColor = .black // default font size public var otpFontSize : CGFloat = 14 // default font for text public var otpFont : UIFont = UIFont.systemFont(ofSize : 14) Example of adaptation override func viewDidLoad() { super.viewDidLoad() otpTextField.otpDelegate = self otpTextField.otpFontSize = 16 otpTextField.otpTextColor = .systemRed otpTextField.otpCornerRaduis = 5 otpTextField.otpFilledBorderColor = .blue otpTextField.configure(with : 4) } }


## GitHub https://github.com/AbdelrhmanKamalEliwa/AEOTPTextFieldSometimes we need to put a text field on a screen which has more than one line of text. For example, the image below shows a text field with three lines of text. The text field does not auto-size itself to the contents of the text field text, but needs to be manually sized and positioned..

Read more about how to add otp textfield in swift and let us know what you think.

Frequently Asked Questions

How do you create a text field in Swift?

It is very common to want to create a text field in iOS using Swift. The Swift textfield control is a flexible, customizable and easy-to-use text field control. It has many features like multi-line input, custom input mask, and various options to enhance the user experience.

Text fields are one of the most commonly-used components on the web. But, did you know that there’s a simple and easy way to create one in Swift? Use a Label for the input field and your app will automatically create a text-based user interface element for the user.

How do you edit text in Swift?

TextField is a simple and easy text field control written in Swift for iOS development. It supports wrap text, placeholder text and automatic line breaks. It is a simple and easy text field control written in Swift. It supports wrap text, placeholder text and automatic line breaks.

Code introduced in iOS 7’s new text editing functionality is fairly robust, but it has some obvious limitations—such as not allowing you to make many changes to the text you’re editing. In this tutorial, we’ll show you how to extend this functionality by creating your own text editor.

What is text field in IOS?

In IOS, when a user attempts to type something, the keyboard pops up and is displayed underneath the area the user is typing. This is called a text field. In Swift, you can create a text field by extending UITextField and implementing the following methods: textFieldDidBeginEditing, textFieldDidEndEditing, textFieldDidBeginGeneratingContent, and textFieldDidEndGeneratingContent.

Text fields in iOS are used to type text in the UI. You use them for text message, email, note, text enter and input tokens.  They are UITextField which is used for .NET programing. It allows you to set the maximum length and the minimum length of the text.  You can also use the setEditable property to allow or disallow editing, and set the text of the field to editable or read only.