iOS Developer Library

Developer

UIKit Framework Reference UITextInputTraits Protocol Reference

Options
Deployment Target:

On This Page
Language:

UITextInputTraits

The UITextInputTraits protocol defines features associated with keyboard input to a text object. For a custom text object to support keyboard input, it must adopt this protocol to interact properly with the text input management system. The UITextField and UITextView classes automatically support this protocol.

  • The auto-capitalization style for the text object.

    Declaration

    Swift

    optional var autocapitalizationType: UITextAutocapitalizationType { get set }

    Objective-C

    @property(nonatomic) UITextAutocapitalizationType autocapitalizationType

    Discussion

    This property determines at what times the Shift key is automatically pressed, thereby making the typed character a capital letter. The default value for this property is UITextAutocapitalizationTypeSentences.

    Some keyboard types do not support auto-capitalization. Specifically, this option is ignored if the value in the keyboardType property is set to UIKeyboardTypeNumberPad, UIKeyboardTypePhonePad, or UIKeyboardTypeNamePhonePad.

    Availability

    Available in iOS 2.0 and later.

  • The autocorrection style for the text object.

    Declaration

    Swift

    optional var autocorrectionType: UITextAutocorrectionType { get set }

    Objective-C

    @property(nonatomic) UITextAutocorrectionType autocorrectionType

    Discussion

    This property determines whether autocorrection is enabled or disabled during typing. With autocorrection enabled, the text object tracks unknown words and suggests a more suitable replacement candidate to the user, replacing the typed text automatically unless the user explicitly overrides the action.

    The default value for this property is UITextAutocorrectionTypeDefault, which for most input methods results in autocorrection being enabled.

    Availability

    Available in iOS 2.0 and later.

  • The spell-checking style for the text object.

    Declaration

    Swift

    optional var spellCheckingType: UITextSpellCheckingType { get set }

    Objective-C

    @property(nonatomic) UITextSpellCheckingType spellCheckingType

    Discussion

    This property determines whether spell-checking is enabled or disabled during typing. With spell-checking enabled, the text object generates red underlines for all misspelled words. If the user taps on a misspelled word, the text object presents the user with a list of possible corrections.

    The default value for this property is UITextSpellCheckingTypeDefault, which enables spell-checking when autocorrection is also enabled. The value in this property overrides the spell-checking setting set by the user in Settings > General > Keyboard.

    Availability

    Available in iOS 5.0 and later.

  • A Boolean value indicating whether the Return key is automatically enabled when the user is entering text.

    Declaration

    Swift

    optional var enablesReturnKeyAutomatically: Bool { get set }

    Objective-C

    @property(nonatomic) BOOL enablesReturnKeyAutomatically

    Discussion

    The default value for this property is NOfalse. If you set it to YEStrue, the keyboard disables the Return key when the text entry area contains no text. As soon as the user enters some text, the Return key is automatically enabled.

    Availability

    Available in iOS 2.0 and later.

  • The appearance style of the keyboard that is associated with the text object

    Declaration

    Swift

    optional var keyboardAppearance: UIKeyboardAppearance { get set }

    Objective-C

    @property(nonatomic) UIKeyboardAppearance keyboardAppearance

    Discussion

    This property lets you distinguish between the default text entry inside your application and text entry inside an alert panel. The default value for this property is UIKeyboardAppearanceDefault.

    Availability

    Available in iOS 2.0 and later.

  • The keyboard style associated with the text object.

    Declaration

    Swift

    optional var keyboardType: UIKeyboardType { get set }

    Objective-C

    @property(nonatomic) UIKeyboardType keyboardType

    Discussion

    Text objects can be targeted for specific types of input, such as plain text, email, numeric entry, and so on. The keyboard style identifies what keys are available on the keyboard and which ones appear by default. The default value for this property is UIKeyboardTypeDefault.

    Availability

    Available in iOS 2.0 and later.

  • The visible title of the Return key.

    Declaration

    Swift

    optional var returnKeyType: UIReturnKeyType { get set }

    Objective-C

    @property(nonatomic) UIReturnKeyType returnKeyType

    Discussion

    Setting this property to a different key type changes the visible title of the Return key and typically results in the keyboard being dismissed when it is pressed. The default value for this property is UIReturnKeyDefault.

    Availability

    Available in iOS 2.0 and later.

  • Identifies whether the text object should hide the text being entered.

    Declaration

    Swift

    optional var secureTextEntry: Bool { get set }

    Objective-C

    @property(nonatomic, getter=isSecureTextEntry) BOOL secureTextEntry

    Discussion

    This property is set to NOfalse by default. Setting this property to YEStrue creates a password-style text object, which hides the text being entered.

    Availability

    Available in iOS 2.0 and later.

  • The auto-capitalization behavior of a text-based view. Used with the autocapitalizationType property.

    Declaration

    Swift

    enum UITextAutocapitalizationType : Int { case None case Words case Sentences case AllCharacters }

    Objective-C

    typedef enum : NSInteger { UITextAutocapitalizationTypeNone, UITextAutocapitalizationTypeWords, UITextAutocapitalizationTypeSentences, UITextAutocapitalizationTypeAllCharacters, } UITextAutocapitalizationType;

    Constants

    • none

      UITextAutocapitalizationTypeNone

      Specifies that there is no automatic text capitalization.

      Available in iOS 2.0 and later.

    • words

      UITextAutocapitalizationTypeWords

      Specifies automatic capitalization of the first letter of each word.

      Available in iOS 2.0 and later.

    • sentences

      UITextAutocapitalizationTypeSentences

      Specifies automatic capitalization of the first letter of each sentence.

      Available in iOS 2.0 and later.

    • allCharacters

      UITextAutocapitalizationTypeAllCharacters

      Specifies automatic capitalization of all characters, such as for entry of two-character state abbreviations for the United States.

      Available in iOS 2.0 and later.

    Discussion

    If the script system does not support capitalization, the keyboard input method ignores these constants.

    Some keyboard types do not support auto-capitalization. Specifically, these constants are ignored if the keyboardType property is set to UIKeyboardTypeNumberPad, UIKeyboardTypePhonePad, or UIKeyboardTypeNamePhonePad.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The autocorrection behavior of a text-based view. Used with the autocorrectionType property.

    Declaration

    Swift

    enum UITextAutocorrectionType : Int { case Default case No case Yes }

    Objective-C

    typedef enum : NSInteger { UITextAutocorrectionTypeDefault, UITextAutocorrectionTypeNo, UITextAutocorrectionTypeYes, } UITextAutocorrectionType;

    Constants

    • default

      UITextAutocorrectionTypeDefault

      Specifies an appropriate autocorrection behavior for the current script system.

      Available in iOS 2.0 and later.

    • no

      UITextAutocorrectionTypeNo

      Disables autocorrection behavior.

      Available in iOS 2.0 and later.

    • yes

      UITextAutocorrectionTypeYes

      Enables autocorrection behavior.

      Available in iOS 2.0 and later.

    Discussion

    If the script system does not support inline autocorrection, the keyboard input method ignores these constants.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The spell-checking behavior of a text-based view. Used with the spellCheckingType property.

    Declaration

    Swift

    enum UITextSpellCheckingType : Int { case Default case No case Yes }

    Objective-C

    typedef enum : NSInteger { UITextSpellCheckingTypeDefault, UITextSpellCheckingTypeNo, UITextSpellCheckingTypeYes, } UITextSpellCheckingType;

    Constants

    • default

      UITextSpellCheckingTypeDefault

      Specifies the default spell-checking behavior. The default behavior is to enable spell-checking whenever autocorrection is also enabled.

      Available in iOS 5.0 and later.

    • no

      UITextSpellCheckingTypeNo

      Disables spell-checking behavior.

      Available in iOS 5.0 and later.

    • yes

      UITextSpellCheckingTypeYes

      Enables spell-checking behavior.

      Available in iOS 5.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • The type of keyboard to display for a given text-based view. Used with the keyboardType property.

    Declaration

    Swift

    enum UIKeyboardType : Int { case Default case ASCIICapable case NumbersAndPunctuation case URL case NumberPad case PhonePad case NamePhonePad case EmailAddress case DecimalPad case Twitter case WebSearch static var Alphabet: UIKeyboardType { get } }

    Objective-C

    typedef enum : NSInteger { UIKeyboardTypeDefault, UIKeyboardTypeASCIICapable, UIKeyboardTypeNumbersAndPunctuation, UIKeyboardTypeURL, UIKeyboardTypeNumberPad, UIKeyboardTypePhonePad, UIKeyboardTypeNamePhonePad, UIKeyboardTypeEmailAddress, UIKeyboardTypeDecimalPad, UIKeyboardTypeTwitter, UIKeyboardTypeWebSearch, UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable } UIKeyboardType;

    Constants

    • default

      UIKeyboardTypeDefault

      Specifies the default keyboard for the current input method.

      Available in iOS 2.0 and later.

    • asciiCapable

      UIKeyboardTypeASCIICapable

      Specifies a keyboard that displays standard ASCII characters.

      Available in iOS 2.0 and later.

    • numbersAndPunctuation

      UIKeyboardTypeNumbersAndPunctuation

      Specifies the numbers and punctuation keyboard.

      Available in iOS 2.0 and later.

    • URL

      UIKeyboardTypeURL

      Specifies a keyboard optimized for URL entry. This keyboard type prominently features the period (“.”) and slash (“/”) characters and the “.com” string.

      Available in iOS 2.0 and later.

    • numberPad

      UIKeyboardTypeNumberPad

      Specifies a numeric keypad designed for PIN entry. This keyboard type prominently features the numbers 0 through 9. This keyboard type does not support auto-capitalization.

      Available in iOS 2.0 and later.

    • phonePad

      UIKeyboardTypePhonePad

      Specifies a keypad designed for entering telephone numbers. This keyboard type prominently features the numbers 0 through 9 and the “*” and “#” characters. This keyboard type does not support auto-capitalization.

      Available in iOS 2.0 and later.

    • namePhonePad

      UIKeyboardTypeNamePhonePad

      Specifies a keypad designed for entering a person’s name or phone number. This keyboard type does not support auto-capitalization.

      Available in iOS 2.0 and later.

    • emailAddress

      UIKeyboardTypeEmailAddress

      Specifies a keyboard optimized for entering email addresses. This keyboard type prominently features the at (“@”), period (“.”) and space characters.

      Available in iOS 2.0 and later.

    • decimalPad

      UIKeyboardTypeDecimalPad

      Specifies a keyboard with numbers and a decimal point.

      Available in iOS 4.1 and later.

    • twitter

      UIKeyboardTypeTwitter

      Specifies a keyboard optimized for Twitter text entry, with easy access to the at (“@”) and hash (“#”) characters.

      Available in iOS 5.0 and later.

    • webSearch

      UIKeyboardTypeWebSearch

      Specifies a keyboard optimized for web search terms and URL entry. This keyboard type prominently features the space and period (“.”) characters.

      Available in iOS 7.0 and later.

    • alphabet

      UIKeyboardTypeAlphabet

      Specifies a keyboard optimized for alphabetic entry.

      Use UIKeyboardTypeASCIICapable instead.

      Available in iOS 2.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The appearance of the keyboard used by a text-based view. Used with the keyboardAppearance property.

    Declaration

    Swift

    enum UIKeyboardAppearance : Int { case Default case Dark case Light static var Alert: UIKeyboardAppearance { get } }

    Objective-C

    typedef enum : NSInteger { UIKeyboardAppearanceDefault, UIKeyboardAppearanceDark, UIKeyboardAppearanceLight, UIKeyboardAppearanceAlert, } UIKeyboardAppearance;

    Constants

    • default

      UIKeyboardAppearanceDefault

      Specifies the default keyboard appearance for the current input method. This constant corresponds to the UIKeyboardAppearanceLight value.

      Available in iOS 2.0 and later.

    • dark

      UIKeyboardAppearanceDark

      Specifies a keyboard appearance suitable for a dark UI look.

      Available in iOS 7.0 and later.

    • light

      UIKeyboardAppearanceLight

      Specifies a keyboard appearance suitable for a light UI look.

      Available in iOS 7.0 and later.

    • alert

      UIKeyboardAppearanceAlert

      Specifies a keyboard appearance suitable for an alert panel.

      Use UIKeyboardAppearanceDark instead.

      Available in iOS 2.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The text string displayed in the Return key of a keyboard. Used with the returnKeyType property.

    Declaration

    Swift

    enum UIReturnKeyType : Int { case Default case Go case Google case Join case Next case Route case Search case Send case Yahoo case Done case EmergencyCall case Continue }

    Objective-C

    typedef enum : NSInteger { UIReturnKeyDefault, UIReturnKeyGo, UIReturnKeyGoogle, UIReturnKeyJoin, UIReturnKeyNext, UIReturnKeyRoute, UIReturnKeySearch, UIReturnKeySend, UIReturnKeyYahoo, UIReturnKeyDone, UIReturnKeyEmergencyCall, UIReturnKeyContinue, } UIReturnKeyType;

    Constants

    • default

      UIReturnKeyDefault

      Specifies that the visible title of the Return key is “return”.

      Available in iOS 2.0 and later.

    • go

      UIReturnKeyGo

      Specifies that the visible title of the Return key is “Go”.

      Available in iOS 2.0 and later.

    • google

      UIReturnKeyGoogle

      Specifies that the visible title of the Return key is “Google”.

      Available in iOS 2.0 and later.

    • join

      UIReturnKeyJoin

      Specifies that the visible title of the Return key is “Join”.

      Available in iOS 2.0 and later.

    • next

      UIReturnKeyNext

      Specifies that the visible title of the Return key is “Next”.

      Available in iOS 2.0 and later.

    • route

      UIReturnKeyRoute

      Specifies that the visible title of the Return key is “Route”.

      Available in iOS 2.0 and later.

    • search

      UIReturnKeySearch

      Specifies that the visible title of the Return key is “Search”.

      Available in iOS 2.0 and later.

    • send

      UIReturnKeySend

      Specifies that the visible title of the Return key is “Send”.

      Available in iOS 2.0 and later.

    • yahoo

      UIReturnKeyYahoo

      Specifies that the visible title of the Return key is “Yahoo”.

      Available in iOS 2.0 and later.

    • done

      UIReturnKeyDone

      Specifies that the visible title of the Return key is “Done”.

      Available in iOS 2.0 and later.

    • emergencyCall

      UIReturnKeyEmergencyCall

      Specifies that the visible title of the Return key is “Emergency Call”.

      Available in iOS 2.0 and later.

    • continue

      UIReturnKeyContinue

      Specifies that the visible title of the Return key is “Continue”.

      Available in iOS 9.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.