Pass Code TextField Blocks : TextFields Stack

Abdulmagid Elmaghbub
2 min readJan 22, 2021

so making a pass code that takes 6 digits and each digit looks in a separated block means 6 textFields and management for each one of them aaaaaaand that is a headache.
so i created a TextFieldStack.swift witch is a UIViewController class.
This component is meant to make textFields work together in a stack.

What is it

Change the targeted ViewControler from a UIViewController to TextFieldStack.

Where the TextFieldStack contains 3 methods that you will use:

  • textFieldStackInitializer, with the parameters
    - textFields : [UITextField]
    - action : UIButton
  • setupUnderLineTextFieldsColors, with the parameters
    - normalColor : UIColor
    - activeColor : UIColor
    - errorColor : UIColor
  • getTextNumber, have no parameters

textFieldStackInitializer Method requires the following from the parent controller

  • textFields : witch is an array of the targeted textFields from the left to the right
  • action : is the action that will be enabled once all the text Fields are filled

setupUnderLineTextFieldsColors (optional) where it will allow you to setup your castom colors for your states witch are [ normal, active, error] by default the normalColor = UIColor.lightGray the activeColor = UIColor.systemBlue and the errorColor = UIColor.systemRed so if you don't want to change them you are set to go and if you want to only change one or two of them no problem all the parameters are optional.

getTextNumber a method that gives you the string out of all the textViews.

TextFieldStack

How To Use

and when you are done you can retrieve the total digits as a string you can call up on the getTextNumber()

i hope you find this in use.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Abdulmagid Elmaghbub
Abdulmagid Elmaghbub

No responses yet

Write a response