- Inherits from:
- NSControl : NSView : NSResponder : NSObject
- Conforms to:
- NSCoding
- (NSResponder)
- NSObject (NSObject)
Declared in:
- AppKit/NSTextField.h
An NSTextField is a kind of NSControl that displays text that the user can select or edit, and which sends its action message to its target when the user presses the Return key while editing. Like other controls, it also performs validation on its value when edited; if the value isn't valid it sends a special error action message to its target. An NSTextField can be assigned a delegate, who is then informed of delegate messages sent by the window's field editor, such as textShouldEndEditing:. See the NSWindow and NSTextView class specifications for more information on a window's field editor.
Typical of several kinds of control, NSTextField allows you to set its text and background color, whether it draws the background, and whether it draws a bezel or border around its text. Note that the text and background colors of selected text are configurable. The selected text color overshadows any actual text color applied to the text while it's selected (this is generally the case with controls).
You can link text fields together in their window's key view loop, as described in the NSWindow class specification.
- Controlling editability and selectability
- - setEditable:
- - isEditable
- - setSelectable:
- - isSelectable
- Setting the error action
- - setErrorAction:
- - errorAction
- Controlling rich text behavior
- - setAllowsEditingTextAttributes:
- - allowsEditingTextAttributes
- - setImportsGraphics:
- - importsGraphics
- Setting the text color
- - setTextColor:
- - textColor
- Controlling the background
- - setBackgroundColor:
- - backgroundColor
- - setDrawsBackground:
- - drawsBackground
- Setting a border
- - setBezeled:
- - isBezeled
- - setBordered:
- - isBordered
- Linking text fields together
- - setNextText:
- - nextText
- - setPreviousText:
- - previousText
- Selecting the text
- - selectText:
- Working with the responder chain
- - acceptsFirstResponder
- Using keyboard interface control
- - setTitleWithMnemonic:
- Setting the delegate
- - setDelegate:
- - delegate
- Text delegate methods
- - textShouldBeginEditing:
- - textDidBeginEditing:
- - textDidChange:
- - textShouldEndEditing:
- - textDidEndEditing:
- (BOOL)acceptsFirstResponder
YES
if
the receiver is editable or selectable, NO
otherwise.- (BOOL)allowsEditingTextAttributes
YES
if
the receiver allows the user to change font attributes of the receiver's
text, NO
if the user isn't permitted
to do so. You can change text attributes programmatically
regardless of this setting.See Also: - importsGraphics, - setAllowsEditingTextAttributes:
- (NSColor *)backgroundColor
See Also: - drawsBackground, - setBackgroundColor:
- (id)delegate
See Also: - textShouldBeginEditing:, - textShouldEndEditing:, - textDidBeginEditing:, - textDidEndEditing:, - textDidChange:, - setDelegate:
- (BOOL)drawsBackground
YES
if
the receiver's cell draws its background color behind its text, NO
if
it draws no background.See Also: - backgroundColor, - drawsBackground (NSTextFieldCell), - setDrawsBackground:
- (SEL)errorAction
See Also: - textShouldEndEditing:, - setErrorAction:
- (BOOL)importsGraphics
YES
if
the receiver allows the user to drag image files into it, NO
if
it doesn't accept dragged images. You can add
images programmatically regardless of this setting.See Also: - allowsEditingTextAttributes, importsGraphics (NSTextView), - setImportsGraphics:
- (BOOL)isBezeled
YES
if
the receiver draws a bezeled frame around its contents, NO
if
it doesn't.See Also: - isBordered, - setBezeled:
- (BOOL)isBordered
YES
if
the receiver draws a solid black border around its contents, NO
if
it doesn't.See Also: - isBezeled, - setBordered:
- (BOOL)isEditable
YES
if
the user is allowed to select and edit the receiver's text, NO
if
the user isn't allowed to edit it (though the user may be able
to select it).See Also: - isSelectable, - setEditable:
- (BOOL)isSelectable
YES
if
the user is allowed to select the receiver's text, NO
if
the user isn't allowed to select it. Selectable
text isn't necessarily editable; use isEditable to check for editability.See Also: - setSelectable:
- (id)nextText
See Also: - previousText, - setNextText:
- (id)previousText
See Also: - nextText, - setPreviousText:
- (void)selectText:(id)sender
See Also: - isSelectable
- (void)setAllowsEditingTextAttributes:(BOOL)flag
YES
,
the user is permitted to make such changes; if flag is NO
,
the user isn't so permitted. You can change text attributes programmatically
regardless of this setting.See Also: - setImportsGraphics:, - allowsEditingTextAttributes
- (void)setBackgroundColor:(NSColor
*)aColor
See Also: - setDrawsBackground:, - backgroundColor
- (void)setBezeled:(BOOL)flag
NO
,
it draws no border; if flag is YES
,
it draws a bezeled border and invokes setDrawsBackground: with an argument
of NO
.See Also: - isBezeled, - setBordered:
- (void)setBordered:(BOOL)flag
YES
,
then it draws a border; if flag is NO
,
it draws no border.See Also: - isBordered, - setBezeled:
- (void)setDelegate:(id)anObject
See Also: - textShouldBeginEditing:, - textShouldEndEditing:, - textDidBeginEditing:, - textDidEndEditing:, - textDidChange:, - delegate
- (void)setDrawsBackground:(BOOL)flag
YES
,
then it does; if flag is NO
,
then it draws nothing behind its text.See Also: - setBackgroundColor:, - setDrawsBackground: (NSTextFieldCell), - drawsBackground
- (void)setEditable:(BOOL)flag
YES
,
then the user is allowed to both select and edit text. If flag is NO
,
then the user isn't permitted to edit text, and the receiver's selectability
is restored to its previous value. For example, if an NSTextField
is selectable but not editable, then made editable for a time, then
made not editable, it remains selectable. To guarantee that text
is neither editable nor selectable, simply use setSelectable: to turn off selectability.See Also: - isEditable
- (void)setErrorAction:(SEL)aSelector
See Also: - textShouldEndEditing:, - errorAction
- (void)setImportsGraphics:(BOOL)flag
YES
,
the receiver accepts dragged images; if flag is NO
,
it doesn't. You can add images programmatically regardless of this
setting.See Also: - setAllowsEditingTextAttributes:, - setImportsGraphics: (NSTextView), - importsGraphics
See Also: - setPreviousText:, - nextText
- (void)setPreviousText:(id)anObject
See Also: - setNextText:, - previousText
- (void)setSelectable:(BOOL)flag
YES
,
the receiver is made selectable but not editable (use setEditable: to
make text both selectable and editable). If NO
,
then the text is made neither editable nor selectable.See Also: - setEditable:
- (void)setTextColor:(NSColor
*)aColor
See Also: - setBackgroundColor:, - setTextColor: (NSTextFieldCell), - textColor
- (void)setTitleWithMnemonic:(NSString
*)aString
- (NSColor *)textColor
See Also: - backgroundColor, - textColor (NSTextFieldCell), - setTextColor:
- (void)textDidBeginEditing:(NSNotification
*)aNotification
See Also: - textDidBeginEditing:, - textDidChange:, - textShouldEndEditing:, - textDidEndEditing:
- (void)textDidChange:(NSNotification
*)aNotification
See Also: - textShouldBeginEditing:, - textDidBeginEditing:, - textShouldEndEditing:, - textDidEndEditing:
- (void)textDidEndEditing:(NSNotification
*)aNotification
See the NSControl class specification for more information on the text delegate method.
See Also: - textShouldBeginEditing:, - textDidBeginEditing:, - textDidChange:, - textShouldEndEditing:
- (BOOL)textShouldBeginEditing:(NSText
*)textObject
NO
immediately.
If it is editable and its delegate responds to control:textShouldBeginEditing:,
invokes that method and returns the result. Otherwise simply returns YES
to
allow editing to occur. See the NSControl class specification for
more information on the text delegate method.See Also: - textDidBeginEditing:, - textDidChange:, - textShouldEndEditing:, - textDidEndEditing:
- (BOOL)textShouldEndEditing:(NSText
*)textObject
NO
. See the
NSControl class specification for more information on the text delegate method.See Also: - textShouldBeginEditing:, - textDidBeginEditing:, - textDidChange:, - textDidEndEditing:, - errorAction