Mac Developer Library

Developer

AppKit Framework Reference NSTextField Class Reference

Options
Deployment Target:

On This Page
Language:

NSTextField

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.

The parent class, NSControl, provides the methods for setting the values of the text field, for example: setStringValue:, setDoubleValue:, etc.. There are corresponding methods to retrieve values.

  • A Boolean that controls whether the user can edit the receiver’s text.

    Declaration

    Swift

    var editable: Bool

    Objective-C

    @property(getter=isEditable) BOOL editable

    Discussion

    If YEStrue, then the user is allowed to both select and edit text. If flag is NOfalse, then the user isn’t permitted to edit text and the ability to select the receiver’s content is dependent on the value of selectable.

    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 or selectable, use selectable to disable text selection.

    Availability

    Available in OS X v10.0 and later.

    See Also

    selectable

  • A Boolean that determins whether the receiver is selectable (but not editable).

    Declaration

    Swift

    var selectable: Bool

    Objective-C

    @property(getter=isSelectable) BOOL selectable

    Discussion

    If YEStrue, the receiver is made selectable but not editable (use editable to make text both selectable and editable). If NOfalse, the text is neither editable nor selectable.

    Availability

    Available in OS X v10.0 and later.

    See Also

    editable

  • A Boolean that controls whether the receiver allows the user to change font attributes of the receiver’s string.

    Declaration

    Swift

    var allowsEditingTextAttributes: Bool

    Objective-C

    @property BOOL allowsEditingTextAttributes

    Discussion

    If YEStrue, and the text value is an attributed string, it is displayed using the attributed string’s visual settings, which can be modified in the font panel.; if flag is NOfalse and the text is an attributed string. the string attributes (font, color, etc.) are ignored and the string is displayed based on the text field’s settings. Setting the attributed string’s attributes are ignored when displaying the string and when the text field is editing.

    Availability

    Available in OS X v10.0 and later.

    See Also

    importsGraphics

  • A Boolean that controls whether the receiver allows the user to drag image files into it.

    Declaration

    Swift

    var importsGraphics: Bool

    Objective-C

    @property BOOL importsGraphics

    Discussion

    If YEStrue, the receiver accepts dragged images; if NOfalse, it doesn’t. You can add images programmatically regardless of this setting.

    Availability

    Available in OS X v10.0 and later.

  • The color of the background that the receiver’s cell draws behind the text.

    Declaration

    Swift

    @NSCopying var backgroundColor: NSColor?

    Objective-C

    @property(copy) NSColor *backgroundColor

    Availability

    Available in OS X v10.0 and later.

    See Also

    drawsBackground

  • A Boolean that controls whether the receiver’s cell draws its background color behind its text

    Declaration

    Swift

    var drawsBackground: Bool

    Objective-C

    @property BOOL drawsBackground

    Discussion

    If YEStrue, the receiver’s cell draws its background; if NOfalse, it draws nothing behind its text.

    In order to prevent inconsistent rendering, background color rendering is disabled for rounded-bezel text fields.

    Availability

    Available in OS X v10.0 and later.

    See Also

    backgroundColor
    setDrawsBackground: (NSTextFieldCell)

  • A Boolean that controls whether the receiver draws a bezeled border around its contents.

    Declaration

    Swift

    var bezeled: Bool

    Objective-C

    @property(getter=isBezeled) BOOL bezeled

    Discussion

    If YEStrue, it draws a bezeled border and invokes drawsBackground with an argument of NOfalse; if NOfalse, the receiver does not draw a border.

    Availability

    Available in OS X v10.0 and later.

    See Also

    bordered

  • The receiver’s bezel style.

    Declaration

    Swift

    var bezelStyle: NSTextFieldBezelStyle

    Objective-C

    @property NSTextFieldBezelStyle bezelStyle

    Discussion

    Possible values for style are described in NSTextFieldBezelStyle. You must have already sent the receiver bezeled with an argument of YEStrue

    Availability

    Available in OS X v10.2 and later.

  • A Boolean that controls whether the receiver draws a solid black border around its contents.

    Declaration

    Swift

    var bordered: Bool

    Objective-C

    @property(getter=isBordered) BOOL bordered

    Discussion

    If YEStrue, the receiver draws a border; if NOfalse, it draws no border.

    Availability

    Available in OS X v10.0 and later.

    See Also

    bezeled

  • Ends editing and selects the entire contents of the receiver if it’s selectable.

    Declaration

    Swift

    func selectText(_ sender: AnyObject?)

    Objective-C

    - (void)selectText:(id)sender

    Parameters

    sender

    The sender of the message.

    Discussion

    If the receiver isn’t in some window’s view hierarchy, this method has no effect.

    Availability

    Available in OS X v10.0 and later.

    See Also

    selectable

  • A Boolean value indicating whether the receiver is editable. (read-only)

    Declaration

    Swift

    var acceptsFirstResponder: Bool { get }

    Objective-C

    @property(readonly) BOOL acceptsFirstResponder

    Discussion

    YEStrue if the receiver is editable, NOfalse otherwise.

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s string value, using the embedded character as the keyboard mnemonic.

    Declaration

    Objective-C

    - (void)setTitleWithMnemonic:(NSString *)aString

    Parameters

    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).

    Discussion

    Mnemonics are not supported in OS X.

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.8.