Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/AppKit.framework |
Availability | Available in Mac OS X v10.0 and later. |
Companion guide | |
Declared in | NSTextField.h |
Related sample code |
An NSTextField
object is a kind of NSControl
that displays text that the user can select or edit and that sends its action message to its target when the user presses the Return key while editing.
The NSTextField
class uses the NSTextFieldCell
class to implement its user interface.
– setAllowsEditingTextAttributes:
– allowsEditingTextAttributes
– setImportsGraphics:
– importsGraphics
– textShouldBeginEditing:
– textDidBeginEditing:
– textDidChange:
– textShouldEndEditing:
– textDidEndEditing:
Returns a Boolean value indicating whether the receiver is editable.
- (BOOL)acceptsFirstResponder
YES
if the receiver is editable, NO
otherwise.
NSTextField.h
Returns a Boolean value indicating whether the user is allowed to change font attributes of the receiver's text.
- (BOOL)allowsEditingTextAttributes
YES
if the receiver allows the user to change font attributes of the receiver’s text, otherwise NO
. You can change text attributes programmatically regardless of this setting.
NSTextField.h
Returns the color of the background that the receiver’s cell draws behind the text.
- (NSColor *)backgroundColor
The color used to draw the background.
NSTextField.h
Returns the receiver’s bezel style.
- (NSTextFieldBezelStyle)bezelStyle
A constant indicating the bezel style. Possible values are described in the “Constants” section of NSTextFieldCell.
NSTextField.h
Returns the receiver’s delegate.
- (id)delegate
The object that acts as the receiver's delegate.
– textShouldBeginEditing:
– textShouldEndEditing:
– textDidBeginEditing:
– textDidEndEditing:
– textDidChange:
– setDelegate:
NSTextField.h
Returns a Boolean value indicating whether the receiver's cell draws its background color.
- (BOOL)drawsBackground
YES
if the receiver’s cell draws its background color behind its text, NO
if it draws no background.
In order to prevent inconsistent rendering, background color rendering is disabled for rounded-bezel text fields.
– backgroundColor
– drawsBackground
(NSTextFieldCell
)– setDrawsBackground:
NSTextField.h
Returns a Boolean value indicating whether the receiver allows the user to drag image files into it.
- (BOOL)importsGraphics
YES
if the receiver allows the user to drag image files into it, otherwise NO
. You can add images programmatically regardless of this setting.
NSTextField.h
Returns a Boolean value indicating whether the receiver draws a bezeled frame.
- (BOOL)isBezeled
YES
if the receiver draws a bezeled frame around its contents; otherwise, NO
.
NSTextField.h
Returns a Boolean value indicating whether the receiver draws a black border around its contents.
- (BOOL)isBordered
YES
if the receiver draws a solid black border around its contents; otherwise NO
.
NSTextField.h
Returns a Boolean value indicating whether the user is allowed to select and edit the receiver's text.
- (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).
NSTextField.h
Returns a Boolean value indicating whether the user is allowed to select the receiver’s text.
- (BOOL)isSelectable
YES
if the user is allowed to select the receiver’s text; otherwise NO
.
Selectable text isn’t necessarily editable; use isEditable
to check for editability.
NSTextField.h
Ends editing and selects the entire contents of the receiver if it’s selectable.
- (void)selectText:(id)sender
The sender of the message.
If the receiver isn’t in some window’s view hierarchy, this method has no effect.
NSTextField.h
Controls whether the receiver allows the user to change font attributes of the receiver’s text.
- (void)setAllowsEditingTextAttributes:(BOOL)flag
If YES
, the user is permitted to change font attributes of the receiver’s text; if flag is NO
, the user isn’t so permitted. You can change text attributes programmatically regardless of this setting.
NSTextField.h
Sets the color of the background that the receiver’s cell draws behind the text.
- (void)setBackgroundColor:(NSColor *)aColor
The color used to draw the background.
NSTextField.h
Controls whether the receiver draws a bezeled border around its contents.
- (void)setBezeled:(BOOL)flag
If YES
, it draws a bezeled border and invokes setDrawsBackground:
with an argument of NO
; if NO
, the receiver does not draw a border.
NSTextField.h
Sets the receiver’s bezel style.
- (void)setBezelStyle:(NSTextFieldBezelStyle)style
A constant indicating the bezel style. Possible values for style are described in the “Constants” section of NSTextFieldCell. You must have already sent the receiver setBezeled:
with an argument of YES
NSTextField.h
Controls whether the receiver draws a solid black border around its contents.
- (void)setBordered:(BOOL)flag
NSTextField.h
Sets the receiver’s delegate.
- (void)setDelegate:(id)anObject
The object that acts as the receiver's delegate.
– textShouldBeginEditing:
– textShouldEndEditing:
– textDidBeginEditing:
– textDidEndEditing:
– textDidChange:
– delegate
NSTextField.h
Controls whether the receiver’s cell draws its background color behind its text.
- (void)setDrawsBackground:(BOOL)flag
In order to prevent inconsistent rendering, background color rendering is disabled for rounded-bezel text fields.
– setBackgroundColor:
– setDrawsBackground:
(NSTextFieldCell
)– drawsBackground
NSTextField.h
Controls whether the user can edit the receiver’s text.
- (void)setEditable:(BOOL)flag
If 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
object 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.
NSTextField.h
Controls whether the receiver allows the user to drag image files into it.
- (void)setImportsGraphics:(BOOL)flag
If YES
, the receiver accepts dragged images; if NO
, it doesn’t. You can add images programmatically regardless of this setting.
NSTextField.h
Sets whether the receiver is selectable (but not editable).
- (void)setSelectable:(BOOL)flag
If YES
, the receiver is made selectable but not editable (use setEditable:
to make text both selectable and editable). If NO
, the text is neither editable nor selectable.
NSTextField.h
Sets the color used to draw the receiver’s text.
- (void)setTextColor:(NSColor *)aColor
The color used to draw text.
– setBackgroundColor:
– setTextColor:
(NSTextFieldCell
)– textColor
NSTextField.h
Sets the receiver’s string value, using the embedded character as the keyboard mnemonic.
- (void)setTitleWithMnemonic:(NSString *)aString
The string to set as the title. The first character preceded by an ampersand (‘&’) is used as the mnemonic (the first ampersand character is stripped out).
Mnemonics are not supported in Mac OS X.
NSTextField.h
Returns the color used to draw the receiver’s text.
- (NSColor *)textColor
The color used to draw text.
– backgroundColor
– textColor
(NSTextFieldCell
)– setTextColor:
NSTextField.h
Posts a notification that the text is about to begin editing to the default notification center.
- (void)textDidBeginEditing:(NSNotification *)aNotification
The NSControlTextDidBeginEditingNotification
notification to post.
This action causes the receiver’s delegate to receive a controlTextDidBeginEditing:
message. See the NSControl class specification for more information on the text delegate method.
NSTextField.h
Posts a notification that the text has changed and forwards this message to the receiver’s cell if it responds.
- (void)textDidChange:(NSNotification *)aNotification
The NSControlTextDidChangeNotification
notification that is posted to the default notification center.
This method causes the receiver’s delegate to receive a controlTextDidChange:
message. See the NSControl class specification for more information on the text delegate method.
NSTextField.h
Handles an end of editing.
- (void)textDidEndEditing:(NSNotification *)aNotification
The notification that editing has ended.
After validating the new value, posts an NSControlTextDidEndEditingNotification
to the default notification center. This posting causes the receiver’s delegate to receive a controlTextDidEndEditing:
message. After this message, sends endEditing:
to the receiver’ cell and handles the key that caused editing to end:
If the user ended editing by pressing Return, this method tries to send the receiver’s action to its target; if unsuccessful, it sends performKeyEquivalent:
to its NSView
(for example, to handle the default button on a panel); if that also fails, the receiver simply selects its text.
If the user ended editing by pressing Tab or Shift-Tab, the receiver tries to have its NSWindow
object select its next or previous key view, using the NSWindow
method selectKeyViewFollowingView:
or selectKeyViewPrecedingView:
. If unsuccessful in doing this, the receiver simply selects its text.
See the NSControl class specification for more information on the text delegate method.
NSTextField.h
Requests permission to begin editing a text object.
- (BOOL)textShouldBeginEditing:(NSText *)textObject
The object to begin editing.
YES
if editing should be allowed to occur, NO
otherwise.
If the receiver isn’t editable, returns NO
immediately. If it is editable and its delegate responds to control:textShouldBeginEditing:
, this invokes that method and returns the result. Otherwise it simply returns YES
to allow editing to occur. See the NSControl class specification for more information on the text delegate method.
NSTextField.h
Performs validation on the receiver’s new value.
- (BOOL)textShouldEndEditing:(NSText *)textObject
The text object requesting permission to end editing.
YES
if the new value is valid; otherwise NO
.
This method validates the receiver's new value using the NSCell
method isEntryAcceptable:
. If the new value is valid and the delegate responds to control:textShouldEndEditing:
, invokes that method and returns the result, in addition beeping if the delegate returns NO
. See the NSControl class specification for more information on the text delegate method.
NSTextField.h
© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-01-06)