Mac Developer Library

Developer

AppKit Framework Reference NSFormCell Class Reference

Options
Deployment Target:

On This Page
Language:

NSFormCell

Inheritance


Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.

The NSFormCell class is used to implement text entry fields in a form. The left part of an NSFormCell object contains a title. The right part contains an editable text entry field.

An NSFormCell object implements the user interface of an NSForm object.

  • Returns an NSFormCell object initialized with the specified title string.

    Declaration

    Swift

    init(textCell aString: String?)

    Objective-C

    - (instancetype)initTextCell:(NSString *)aString

    Parameters

    aString

    The title for the new form cell object.

    Return Value

    An initialized NSFormCell object.

    Discussion

    The contents of the cell's editable text entry field are set to the empty string (@“”). The font for both title and text is the user’s chosen system font in 12.0 point, and the text area is drawn with a bezel. This method is the designated initializer for the NSFormCell class.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setTitle:

  • isOpaque - isOpaque Available in OS X v10.0 through OS X v10.9

    Returns a Boolean value indicating whether the title is empty and an opaque bezel is set.

    Declaration

    Objective-C

    - (BOOL)isOpaque

    Return Value

    YEStrue if the title is empty and an opaque bezel is set; otherwise, NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Returns the title of the cell as an attributed string.

    Declaration

    Swift

    @NSCopying var attributedTitle: NSAttributedString

    Objective-C

    @property(copy) NSAttributedString *attributedTitle

    Return Value

    The title of the cell.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s title.

    Declaration

    Swift

    var title: String

    Objective-C

    @property(copy) NSString *title

    Return Value

    The title of the cell. The default value is "Field:".

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the alignment of the title.

    Declaration

    Swift

    var titleAlignment: NSTextAlignment

    Objective-C

    @property NSTextAlignment titleAlignment

    Return Value

    The alignment can be one of the following values: NSLeftTextAlignment, NSCenterTextAlignment, or NSRightTextAlignment. The default alignment is NSRightTextAlignment.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the default writing direction used to render the form cell’s title.

    Declaration

    Swift

    var titleBaseWritingDirection: NSWritingDirection

    Objective-C

    @property NSWritingDirection titleBaseWritingDirection

    Return Value

    One of the following constants: NSWritingDirectionNatural, NSWritingDirectionLeftToRight, or NSWritingDirectionRightToLeft.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns the font used to draw the receiver’s title.

    Declaration

    Swift

    var titleFont: NSFont

    Objective-C

    @property(strong) NSFont *titleFont

    Return Value

    The font object used for the title.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the width of the title field.

    Declaration

    Swift

    var titleWidth: CGFloat

    Objective-C

    @property CGFloat titleWidth

    Return Value

    The width of the title field, measured in points in the user coordinate space.

    Discussion

    If you set the width using setTitleWidth:, this method returns the value you set; otherwise, it returns the width calculated automatically by the Application Kit.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – titleWidth:

  • Returns the width of the title field constrained to the specified size.

    Declaration

    Swift

    func titleWidth(_ aSize: NSSize) -> CGFloat

    Objective-C

    - (CGFloat)titleWidth:(NSSize)aSize

    Parameters

    aSize

    The maximum size of the field when calculated by the Application Kit.

    Return Value

    The width of the title field, measured in points in the user coordinate space.

    Discussion

    If you set the width using setTitleWidth:, this method returns the value you set; otherwise, the Application Kit calculates the width, constraining the field size to the specified value.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – titleWidth

  • Sets the receiver’s title using an attributed string.

    Declaration

    Swift

    @NSCopying var attributedTitle: NSAttributedString

    Objective-C

    @property(copy) NSAttributedString *attributedTitle

    Parameters

    anAttributedString

    The formatted title of the cell.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s title to the specified plain-text string.

    Declaration

    Swift

    var title: String

    Objective-C

    @property(copy) NSString *title

    Parameters

    aString

    The plain-text title of the cell.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the alignment of the title.

    Declaration

    Swift

    var titleAlignment: NSTextAlignment

    Objective-C

    @property NSTextAlignment titleAlignment

    Parameters

    alignment

    The alignment can be one of the following constants: NSRightTextAlignment, NSCenterTextAlignment, or NSLeftTextAlignment.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the default writing direction used to render the form cell’s title.

    Declaration

    Swift

    var titleBaseWritingDirection: NSWritingDirection

    Objective-C

    @property NSWritingDirection titleBaseWritingDirection

    Parameters

    writingDirection

    This value can be one of the following constants: NSWritingDirectionNatural, NSWritingDirectionLeftToRight, or NSWritingDirectionRightToLeft.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Sets the font of the receiver's title.

    Declaration

    Swift

    var titleFont: NSFont

    Objective-C

    @property(strong) NSFont *titleFont

    Parameters

    font

    The font to use.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the width of the title.

    Declaration

    Swift

    var titleWidth: CGFloat

    Objective-C

    @property CGFloat titleWidth

    Parameters

    width

    The width of the title, measured in points in the user coordinate space.

    Discussion

    You usually do not need to invoke this method. The Application Kit automatically sets the title width whenever the title changes. If the automatic width doesn’t suit your needs, though, you can use this method to set the width explicitly.

    Once you have set the width this way, the Application Kit stops setting the width automatically; you must invoke this method every time the title changes. If you want the Application Kit to resume automatic width assignments, invoke this method with a negative width value.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the cell title and mnemonic character.

    Declaration

    Objective-C

    - (void)setTitleWithMnemonic:(NSString *)titleWithAmpersand

    Parameters

    titleWithAmpersand

    The title of the cell, including a mnemonic identifier. To specify the mnemonic character, place an ampersand (&) in the front of the desired character.

    Discussion

    Mnemonics are not supported in OS X.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.8.

    See Also

    – setTitle:

  • Returns the cell’s attributed placeholder string.

    Declaration

    Swift

    @NSCopying var placeholderAttributedString: NSAttributedString?

    Objective-C

    @property(copy) NSAttributedString *placeholderAttributedString

    Return Value

    The attributed placeholder string, or nil if the cell has no attributed placeholder string.

    Discussion

    If this method returns nil, you can also call placeholderString to see if the cell has a plain text placeholder string.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns the cell’s plain text placeholder string.

    Declaration

    Swift

    var placeholderString: String?

    Objective-C

    @property(copy) NSString *placeholderString

    Return Value

    The plain-text placeholder string, or nil if the cell has no plain-text placeholder string.

    Discussion

    If this method returns nil, you can also call placeholderAttributedString to see if the cell has an attributed placeholder string.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Sets the attributed placeholder string for the cell.

    Declaration

    Swift

    @NSCopying var placeholderAttributedString: NSAttributedString?

    Objective-C

    @property(copy) NSAttributedString *placeholderAttributedString

    Parameters

    string

    The attributed placeholder string.

    Discussion

    Note that invoking this method clears out any plain text string set by calling the setPlaceholderString: method.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Sets the plain-text placeholder string for the cell.

    Declaration

    Swift

    var placeholderString: String?

    Objective-C

    @property(copy) NSString *placeholderString

    Parameters

    string

    The plain-text placeholder string.

    Discussion

    Note that invoking this method clears out any attributed string set by the setPlaceholderAttributedString: method.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns the preferred text field width.

    Declaration

    Swift

    var preferredTextFieldWidth: CGFloat

    Objective-C

    @property CGFloat preferredTextFieldWidth

    Return Value

    Returns the preferred width which will be large enough to accommodate the title, bezel, and a text field of width preferredTextFieldWidth.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.8 and later.

  • Sets the preferred text field width.

    Declaration

    Swift

    var preferredTextFieldWidth: CGFloat

    Objective-C

    @property CGFloat preferredTextFieldWidth

    Parameters

    preferredWidth

    The the preferred width which will be large enough to accommodate the title, bezel, and a text field of width preferredTextFieldWidth.

    Discussion

    The preferred width is reflected in the cell's cellSize, which will be large enough to accommodate the title, bezel, and a text field of width preferredTextWidth. It is also reflected in the intrinsicContentSize of the NSForm. That is, under Auto Layout, the form will try to size itself so that the text field cell is the given width, according to the usual content size constraint priorities.

    If the width is negative, the cellSize matches the historic behavior, which is that it is large enough to accommodate the title, bezel, and the current text.

    This method can aid migration to Auto Layout, and is sufficient for simple cases. However, for new apps, prefer to use NSTextField instance directly instead of forms.

    The default is -1.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.8 and later.