قالب وردپرس درنا توس
Home / IOS Development / # 299: Build better forms with UITextField Navigation 🗺 – Little Bites of Cocoa

# 299: Build better forms with UITextField Navigation 🗺 – Little Bites of Cocoa



Subjects

Topics

Building good forms for users to enter information on iOS is tough. There are many small details that are easy to get wrong. Today, we begin to look at ways to improve this process.

First up is navigation . 📍

For quick and easy navigation from one form field to the next, dramatically can reduce friction for users.

We use a great new library from Thanh Pham called UITextField-Navigation to pull this off. Let's get started.

UITextField-Navigation is built around the concept of telling each field which field should be "next" in the form.

] Once we've done it for all our fields, the library will override and automatically display a navigation bar across the keyboard:

We can easily put these conditions super easily into Interface Builder :

… or in Code:

  la    nameTextField    =   UITextField   () 
 ]   bioTextView    =    =    bioTextView 

Now, when a user starts editing a UITextField or UITextView in our app, a ] UIAppearance to customize the appearance of the toolbar : : :

We can use UIAppearance 19659025] NavigationFieldToolbar . [19659031] Appearance () . barStyle = . black
NavigationFieldToolbar . appearance () . [19659024] background color = UIColor . purple
NavigationFieldToolbarButtonItem . appearance () . tintColor = [19659015] white

Last but not least, we are not limited to a "standard" set of buttons / items in the toolbar . [19659000] We use navigationFieldToolBar optional property as the library adds UITextField and UITextView to First Customize Some Individual Properties ] Direct:

  Guard    La    Toolbar    =    NameTextField .   navigation barToolbar    else    {[19659061] return  } 

  tool .   barStyle    =  .   standard 
  tool .   background color    =   UIColor .   red 
  toolbar .   previousButton .   Title    =    "Backward" 
  Toolbar . [19659024] nextButton .   Title    =    "Onward!" 
  toolbar .   doneButton .       =    "Reject             =       

] :

     "Expand"  
    style : [19659014]   delete  
    target . 

     ]  :    #   Select   (  expandForm ) 
) 

  La    Flexible    =   UIBarButtonItem   (
    barButtonSystemItem .      flexibleSpace  [19659142] target :    nil  
    action  .    nil 
) 

  toolbar    items    =    [
    tool .   previousButton  
    tool .   nextButton  
    Flexible  
    expandButton  [19659155]  ] 
    Toolbar .   doneButton 
] 

Tidy!

Learn more about UITextField Navigation at git.io/textfieldnav.


Source link