OTP View In  Xamarin iOS
Tags: otp, otpview, otpviewinxamarin, passcodeview
Published: 2020-02-02 09:07:36

---
title: OTP View In  Xamarin iOS
published: true
date: 2020-01-24 18:38:00 UTC
tags: OTP,OTP View,OTP View in Xamarin ,Passcode View
canonical_url: https://logeshpalani.blogspot.com/2020/01/otp-view-in-xamarin-ios.html
---

[![](https://1.bp.blogspot.com/-Wor7tJnb6oQ/Xis4bRAxgwI/AAAAAAAAPxc/ZnqRvAecpkIuB_2N-BTO3XdaJHu2FIf9QCLcBGAsYHQ/s640/OTP%2BView%2Bin%2BXamarin%2BiOS.png)](https://1.bp.blogspot.com/-Wor7tJnb6oQ/Xis4bRAxgwI/AAAAAAAAPxc/ZnqRvAecpkIuB_2N-BTO3XdaJHu2FIf9QCLcBGAsYHQ/s1600/OTP%2BView%2Bin%2BXamarin%2BiOS.png)

### 

### Introduction 

In this demonstration, I will explain how to create OTP View in Xamarin iOS without using third party plugins.

  

[![](https://1.bp.blogspot.com/-emMsUjsEw5E/Xis1dD53X1I/AAAAAAAAPxU/EH6sHd1xl6kKL0hTz9QkRDS6DZSUiSIKwCEwYBhgL/s320/ezgif.com-video-to-gif%2B%25281%2529.gif)](https://1.bp.blogspot.com/-emMsUjsEw5E/Xis1dD53X1I/AAAAAAAAPxU/EH6sHd1xl6kKL0hTz9QkRDS6DZSUiSIKwCEwYBhgL/s1600/ezgif.com-video-to-gif%2B%25281%2529.gif)

  

### Issue 

  

First, I'm using a third-party plugin to archive my required view, but there is some issue to customize the view.

### 

## Solution 

### Prerequisites 

- Visual Studio for Mac
- XCode ( Optional )
- Simulator or Physical Device

### Step 1:

              Open Visual Studio for Mac >> New >> In the left plane select App under iOS >> center plane select Single View App >> click Next.

  

[![](https://1.bp.blogspot.com/-cPrpccKXABI/Xisvqv7h_NI/AAAAAAAAPwc/b2dWi3iuWpQliib7_7_pFmB_AFnNa9tbQCLcBGAsYHQ/s320/Screenshot%2B2020-01-23%2Bat%2B7.55.03%2BPM.png)](https://1.bp.blogspot.com/-cPrpccKXABI/Xisvqv7h_NI/AAAAAAAAPwc/b2dWi3iuWpQliib7_7_pFmB_AFnNa9tbQCLcBGAsYHQ/s1600/Screenshot%2B2020-01-23%2Bat%2B7.55.03%2BPM.png)

  

### Step 2:

             Next, give your Application Name, Device type, Identifier, select target Version and click OK.

[![](https://1.bp.blogspot.com/-iEC2Oy_A2-Q/XisvqlxILJI/AAAAAAAAPw4/mSSYing3lbs20yz0VfQVzAoDFuMCHjH5wCEwYBhgL/s320/Screenshot%2B2020-01-23%2Bat%2B7.55.16%2BPM.png)](https://1.bp.blogspot.com/-iEC2Oy_A2-Q/XisvqlxILJI/AAAAAAAAPw4/mSSYing3lbs20yz0VfQVzAoDFuMCHjH5wCEwYBhgL/s1600/Screenshot%2B2020-01-23%2Bat%2B7.55.16%2BPM.png)

  

  

Followed by check the app name and solution name, then click Create.

  

[![](https://1.bp.blogspot.com/-LZcJcLYY-rA/Xisvq6P0_dI/AAAAAAAAPw8/x3zTqqylTdMyR4O5sEC58J9UbYmCNt-BACEwYBhgL/s320/Screenshot%2B2020-01-23%2Bat%2B7.55.29%2BPM.png)](https://1.bp.blogspot.com/-LZcJcLYY-rA/Xisvq6P0_dI/AAAAAAAAPw8/x3zTqqylTdMyR4O5sEC58J9UbYmCNt-BACEwYBhgL/s1600/Screenshot%2B2020-01-23%2Bat%2B7.55.29%2BPM.png)

  

  

### **Step 3:**

                  Now, open Storyboard in your interface builder using the right click of Main.Storyboard >> In the context menu select _Open with  >>_ followed by XCode Interface Builder because my favorite designer is Xcode.

  

[![](https://1.bp.blogspot.com/-8aZ87Lyzd7A/XZZKr1Wv0MI/AAAAAAAAPGE/hYAg1aLP62gtrU2jPSIKEcuIKwd7kn8SACPcBGAYYCw/s320/Xamarin%2BiOS%2B3.png)](https://1.bp.blogspot.com/-8aZ87Lyzd7A/XZZKr1Wv0MI/AAAAAAAAPGE/hYAg1aLP62gtrU2jPSIKEcuIKwd7kn8SACPcBGAYYCw/s1600/Xamarin%2BiOS%2B3.png)

  

              Afterward, Drag Horizontal Stack View from Toolbox and place Storyboard as per your requirement and set perfect Constraint to this view. Next, drag TextField from Toolbox and place inside the StackView and set height and width of TextField. Create an outlet for this TextField to access from code-behind. Here, I set field names are fieldOne, fieldTwo, fieldThree, fieldFour.

| [![](https://1.bp.blogspot.com/-cE_YXxQC7vw/Xisvrxz3sgI/AAAAAAAAPxE/1VToQXPR0yIGFnZ5WgsjMqeqvrlpxEHXQCEwYBhgL/s320/Screenshot%2B2020-01-23%2Bat%2B8.10.55%2BPM.png)](https://1.bp.blogspot.com/-cE_YXxQC7vw/Xisvrxz3sgI/AAAAAAAAPxE/1VToQXPR0yIGFnZ5WgsjMqeqvrlpxEHXQCEwYBhgL/s1600/Screenshot%2B2020-01-23%2Bat%2B8.10.55%2BPM.png) |
| Stack View |

  

| [![](https://1.bp.blogspot.com/-mHyyM7aPJ2w/XisvsrPDaxI/AAAAAAAAPxI/Bt4YtBFuyrQ0mj5vqzRjno7ULNi5kcUNwCEwYBhgL/s320/Screenshot%2B2020-01-23%2Bat%2B8.11.06%2BPM.png)](https://1.bp.blogspot.com/-mHyyM7aPJ2w/XisvsrPDaxI/AAAAAAAAPxI/Bt4YtBFuyrQ0mj5vqzRjno7ULNi5kcUNwCEwYBhgL/s1600/Screenshot%2B2020-01-23%2Bat%2B8.11.06%2BPM.png) |
| OTP View Xamarin iOS |

  

### **Step 4:**

              Next, open ViewController.cs file by going >> Solution Explorer >>  double click ViewController.cs file. Implement the ViewController class in IUITextFieldDelegate interface and override ShouldChangeCharacters method. Here, I did simple logic to change the focus of one field to another field. In case you need to validate input in runtime, you can write your validation code before the ResignResponder method.

  

[![](https://1.bp.blogspot.com/-IVY2qLxwrU4/XisvrVLC32I/AAAAAAAAPxA/fEhPhFYAlkchUSbGzzwJI8VA1_rDmZNsgCEwYBhgL/s320/Screenshot%2B2020-01-23%2Bat%2B7.55.52%2BPM.png)](https://1.bp.blogspot.com/-IVY2qLxwrU4/XisvrVLC32I/AAAAAAAAPxA/fEhPhFYAlkchUSbGzzwJI8VA1_rDmZNsgCEwYBhgL/s1600/Screenshot%2B2020-01-23%2Bat%2B7.55.52%2BPM.png)

  

### Step 5:

Let's run your application, you will get output like below.

  

[![](https://1.bp.blogspot.com/-emMsUjsEw5E/Xis1dD53X1I/AAAAAAAAPxQ/76TBKViXW2IREn3WJl74d7Q3LfN6HTihwCLcBGAsYHQ/s320/ezgif.com-video-to-gif%2B%25281%2529.gif)](https://1.bp.blogspot.com/-emMsUjsEw5E/Xis1dD53X1I/AAAAAAAAPxQ/76TBKViXW2IREn3WJl74d7Q3LfN6HTihwCLcBGAsYHQ/s1600/ezgif.com-video-to-gif%2B%25281%2529.gif)

  

  

The full source code is [here](https://github.com/logeshpalani98/Xamarin.iOS-Samples).

  

### Summary

1. We created StackView
2. StackView inside placed TextField
3. Create an outlet for Textfield
4. Implement IUXTextFieldDelegate to your View Controller and write some logic

Share, your comment below.