iOS Guides | Samples

MonoTouch.UIKit.UITextField Class

A text entry control.

See Also: UITextField


[MonoTouch.Foundation.Register("UITextField", true)]
public class UITextField : UIControl, IUIContentSizeCategoryAdjusting, IUITextInput, IDisposable


The MonoTouch API supports two styles of event notification: the Objective-C style that uses a delegate class or the C# style using event notifications.

The C# style allows the user to add or remove event handlers at runtime by assigning to the events of properties of this class. Event handlers can be anyone of a method, an anonymous methods or a lambda expression. Using the C# style events or properties will override any manual settings to the Objective-C Delegate or WeakDelegate settings.

The Objective-C style requires the user to create a new class derived from UITextFieldDelegate class and assign it to the UIKit.Delegate property. Alternatively, for low-level control, by creating a class derived from NSObject which has every entry point properly decorated with an [Export] attribute. The instance of this object can then be assigned to the UITextField.WeakDelegate property.

Related content


Namespace: MonoTouch.UIKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions:

The members of MonoTouch.UIKit.UITextField are listed below.

See Also: UIControl

Public Constructors

Default constructor that initializes a new instance of this class with no parameters.
A constructor that initializes the object from the data stored in the unarchiver object.
Constructor to call on derived classes to skip initialization and merely allocate the object.
Initializes the UITextField with the specified frame.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

Public Properties

AdjustsFontSizeToFitWidthBoolean. A stem.Boolean that controls if the font should be scaled down to ensure the text fits in the control.
AllowsEditingTextAttributesBoolean. Whether text entered or pasted can change the attributes of the content.
AppearanceUITextField+UITextFieldAppearance. Strongly-typed property that returns the UIAppearance class for this class.
AttributedPlaceholderNSAttributedString. Sets the contents of the placeholder as an attributed string.
AttributedTextNSAttributedString. Sets the contents of the text field using an attributed string.
AutocapitalizationTypeUITextAutocapitalizationType. This property controls how words should be capitalized by the system during user input.
AutocorrectionTypeUITextAutocorrectionType. This property controls how auto-correction should be applied by the system during user input.
BackgroundUIImage. This property contains the image that will be displayed in the background of the control when it is enabled.
BeginningOfDocumentUITextPosition. Specifies the text position that is the start of the document. Read-only.
BorderStyleUITextBorderStyle. The border style.
ClassHandleIntPtr. The handle for this class.
ClearButtonModeUITextFieldViewMode. This property controls when the 'clear' button appears in the text field.
ClearsOnBeginEditingBoolean. This property indicates if the control will delete any existing text before editing.
ClearsOnInsertionBoolean. Whether a paste operation should replace existing content.
CurrentInputModeDidChangeNotificationNSString. Notification constant for CurrentInputModeDidChange
DelegateUITextFieldDelegate. An instance of the MonoTouch.UIKit.UITextFieldDelegate model class which acts as the class delegate.
DisabledBackgroundUIImage. The image to display in the background when the control is disabled.
EnablesReturnKeyAutomaticallyBoolean. A value that control if the return key is automatically enabled.
EndOfDocumentUITextPosition. The text position for the end of the document.
FontUIFont. The font to use for displaying the text.
HasTextBoolean. A value representing if there is text in the view.
InputAccessoryViewUIView. A custom view to display when this control becomes the first responder.
InputDelegateUITextInputDelegate. The input delegate object for this UITextField.
InputViewUIView. A custom view to be used when the control becomes the first responder.
IsEditingBoolean. A value that indicates if the user is editing the text in the view. Read-only.
KeyboardAppearanceUIKeyboardAppearance. The style of the keyboard that is used with the view.
KeyboardTypeUIKeyboardType. The type of keyboard to use with the view.
LeftViewUIView. An overlay that is displayed on the left side of the view.
LeftViewModeUITextFieldViewMode. A property that determines when the UITextField.LeftView will be displayed.
MarkedTextRangeUITextRange. The range of marked text in the document. Read-only.
MarkedTextStyleNSDictionary. A NSDictionary of attributes describing style of the UITextField.MarkedTextRange.
MinimumFontSizeSingle. This property represents the smallest font size that may be used for the text.
PlaceholderString. This property represents the text to be displayed when there is no text in the view.
ReturnKeyTypeUIReturnKeyType. The property is used to get or set the UIReturnKeyType of the "return" key. The "return" key will display different text depending on this property.
RightViewUIView. This property holds a overlay that will be displayed on the right side of the text field.
RightViewModeUITextFieldViewMode. This property controls when the UITextField.RightView will appear.
SecureTextEntryBoolean. This property controls if the text being displayed should be hidden.
SelectedTextRangeUITextRange. This property returns the range of text that is selected.
SelectionAffinityUITextStorageDirection. Sets a value that controls whether the cursor is displayed at the start of the last line or end of the second-to-last line of a multiline selection.
ShouldBeginEditingUITextFieldCondition. Delegate invoked by the object to get a value.
ShouldChangeCharactersUITextFieldChange. Delegate invoked by the object to get a value.
ShouldClearUITextFieldCondition. Delegate invoked by the object to get a value.
ShouldEndEditingUITextFieldCondition. Delegate invoked by the object to get a value.
ShouldReturnUITextFieldCondition. Delegate invoked by the object to get a value.
SpellCheckingTypeUITextSpellCheckingType. This property controls if spell checking will be enabled or disabled during input.
TextString. The text to display.
TextAlignmentUITextAlignment. How the UITextField.Text should be aligned.
TextBackgroundColorKeyNSString. The property holds the key that should be used to retrieve the background color of text from a NSDictionary.
TextColorUIColor. The color of the UITextField.Text.
TextColorKeyNSString. The property holds the key that should be used to retrieve the value of the text color from a NSDictionary.
TextContentTypeNSString. A hint of the type of data the field should contain (must be value from UITextContentType).
TextDidBeginEditingNotificationNSString. Notification constant for TextDidBeginEditing
TextDidEndEditingNotificationNSString. Notification constant for TextDidEndEditing
TextFieldTextDidChangeNotificationNSString. Notification constant for TextFieldTextDidChange
TextFontKeyNSString. The property holds the key that should be used to retrieve the value of the font for the text from a NSDictionary.
TextInputViewUIView. This the view that provides the coordinate system. Read-only.
TokenizerUITextInputTokenizer. This property provides information on the tokenizer that would be used to break up the text into units such as characters, words, lines, and paragraphs.
TypingAttributesNSDictionary. The attribute keys to apply to newly typed text.
WeakDefaultTextAttributesNSDictionary. A reference to the text attributes that does not prevent garbage collection.
WeakDelegateNSObject. An object that can respond to the delegate protocol for this type
WeakInputDelegateNSObject. An object that can respond to the delegate protocol for inserted text.
WeakTokenizerNSObject. This property provides information on the tokenizer that would be used to break up the text into units such as characters, words, lines, and paragraphs.

Public Methods

AppearanceWhenContainedIn(params Type[]) : UITextField+UITextFieldAppearance
Returns a strongly typed UIAppearance for instances of this class when the view is hosted in the specified hierarchy.
Begins displaying the floating cursor at the specified point.
BorderRect(RectangleF) : RectangleF
Returns the border rectangle.
ClearButtonRect(RectangleF) : RectangleF
Returns a rectangle for drawing the 'clear' button.
ComparePosition(UITextPosition, UITextPosition) : NSComparisonResult
Returns a value that shows how one location in a document that compares to another location: before, identical, or after.
This method will delete one character backward of the cursor.
This method is called when dictation has completed and failed.
Called when dictation finished.
Will draw the placeholder text in the provided rectangle.
Will draw the text in the provided rectangle.
EditingRect(RectangleF) : RectangleF
Returns the rectangle to display the editable text.
Ends display of the floating cursor.
GetAppearance(UITraitCollection) : UITextField+UITextFieldAppearance
Returns an appearance proxy for the specified traits.
GetAppearance(UITraitCollection, params Type[]) : UITextField+UITextFieldAppearance
Returns an appearance proxy for the specified traits.
GetAppearance<T>() : UITextField+UITextFieldAppearance
Obtains the appearance proxy UITextFieldAppearance for the subclass of UITextField.
GetAppearance<T>(UITraitCollection) : UITextField+UITextFieldAppearance
Obtains the appearance proxy UITextFieldAppearance for the subclass of UITextField.
GetAppearance<T>(UITraitCollection, params Type[]) : UITextField+UITextFieldAppearance
Obtains the appearance proxy UITextFieldAppearance for the subclass of UITextField that has the specified trait collection when the view is hosted in the specified hierarchy.
GetBaseWritingDirection(UITextPosition, UITextStorageDirection) : UITextWritingDirection
Determines the writing direction from a position within the text.
GetCaretRectForPosition(UITextPosition) : RectangleF
This method will return a rectangle that can be used for drawing the insertion caret.
GetCharacterOffsetOfPosition(UITextPosition, UITextRange) : Int32
Returns the number of characters in some text between position and the start of the range.
GetCharacterRange(UITextPosition, UITextLayoutDirection) : UITextRange
Returns a range that represents the distance from byExtendingPosition to as far as is possible in direction.
GetCharacterRangeAtPoint(PointF) : UITextRange
Returns the character or characters at the point specified.
GetClosestPositionToPoint(PointF) : UITextPosition
Returns the position that is closest to the point specified within the control.
GetClosestPositionToPoint(PointF, UITextRange) : UITextPosition
Returns the position in withinRange that is closest to withinRange.
GetFirstRectForRange(UITextRange) : RectangleF
Returns a rectangle that will enclose the first line of text in the range (if the range specifies multiple lines of text).
GetFrameForDictationResultPlaceholder(NSObject) : RectangleF
The frame in which the dictation results should be displayed.
GetOffsetFromPosition(UITextPosition, UITextPosition) : Int32
Returns the number of characters between two visible locations in a document.
GetPosition(UITextPosition, Int32) : UITextPosition
Returns a second position that is offset from the specified position.
GetPosition(UITextRange, Int32) : UITextPosition
Returns a position within a document relative to the start of withinRange.
GetPosition(UITextPosition, UITextLayoutDirection, Int32) : UITextPosition
Returns a second position in a document the direction and offset relative to the first position.
GetPositionWithinRange(UITextRange, UITextLayoutDirection) : UITextPosition
Returns the furthest position possible in the visible text.
GetSelectionRects(UITextRange) : UITextSelectionRect[]
An array of UITextSelectionRects that frame the range.
GetTextRange(UITextPosition, UITextPosition) : UITextRange
Returns the text range between two positions in a document.
GetTextStyling(UITextPosition, UITextStorageDirection) : NSDictionary
Returns a NSDictionary of styling properties at the position and in the direction specified.
Used to select a UIDictationPhrase from a collection of possible phrases.
InsertDictationResultPlaceholder() : NSObject
When overridden, can be used to provide information for UITextField.GetFrameForDictationResultPlaceholder.
This method will insert text into the view at the position indicated by the cursor.
LeftViewRect(RectangleF) : RectangleF
Returns the rectangle in which the UITextField.LeftView should be displayed.
PlaceholderRect(RectangleF) : RectangleF
This property represents the rectangle that is used to draw the UITextField.PlaceHolder text.
RemoveDictationResultPlaceholder(NSObject, Boolean)
With UITextField.InsertDictationResultPlaceholder, allows the app developer to customize the location of the placeholder for dictation results.
ReplaceText(UITextRange, String)
Replaces text in the specified range with the text provided.
RightViewRect(RectangleF) : RectangleF
This method will return the location of the UITextField.RightView.
SetBaseWritingDirectionforRange(UITextWritingDirection, UITextRange)
Sets the writing direction for a given range of text.
SetMarkedText(String, NSRange)
This method will replace any existing marked text the specified text and then selects it.
ShouldChangeTextInRange(UITextRange, String) : Boolean
Allows the app developer to programmatically reject replacement text.
TextInRange(UITextRange) : String
A substring of text in the range.
TextRect(RectangleF) : RectangleF
This method return the computed rectangle for drawing the text.
Any currently marked text is unmarked.
Moves the floating curor to the specified point.

Protected Methods

Releases the resources used by the UITextField object.

Public Events

EndedRaised when editing has ended.
StartedRaised when editing has started.