Mac Developer Library

Developer

AppKit Framework Reference NSForm Class Reference

Options
Deployment Target:

On This Page
Language:

NSForm

An NSForm object is a vertical matrix of NSFormCell objects to implement the fields.

Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.
Deprecated in OS X v10.10.
  • addEntry(_:) - addEntry: (OS X v10.10)

    Adds a new entry to the end of the receiver and gives it the specified title.

    Declaration

    Swift

    func addEntry(_ title: String) -> NSFormCell

    Objective-C

    - (NSFormCell *)addEntry:(NSString *)title

    Parameters

    title

    The title for the new form entry.

    Return Value

    The form cell object that was created for the entry.

    Discussion

    The new entry has no tag, target, or action, but is enabled and editable.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

    See Also

    – insertEntry:atIndex:
    setEditable: (NSCell)
    setTag: (NSActionCell)
    setTarget: (NSActionCell)
    setAction: (NSActionCell)
    setEnabled: (NSCell)

  • Inserts an entry with the specified title into the receiver.

    Declaration

    Swift

    func insertEntry(_ title: String, atIndex entryIndex: Int) -> NSFormCell!

    Objective-C

    - (NSFormCell *)insertEntry:(NSString *)title atIndex:(NSInteger)entryIndex

    Parameters

    title

    The title for the new form entry.

    entryIndex

    The zero-based index at which to insert the entry.

    Return Value

    The form cell object that was created for the entry.

    Discussion

    The new entry has no tag, target, or action, but is enabled and editable.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Removes and releases the entry at the specified index.

    Declaration

    Swift

    func removeEntryAtIndex(_ entryIndex: Int)

    Objective-C

    - (void)removeEntryAtIndex:(NSInteger)entryIndex

    Parameters

    entryIndex

    The zero-based index identifying the desired entry.

    Discussion

    If the specified index is invalid, this method does nothing.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Sets whether the receiver's entries should display a bezel around their editable text.

    Declaration

    Swift

    func setBezeled(_ flag: Bool)

    Objective-C

    - (void)setBezeled:(BOOL)flag

    Parameters

    flag

    YEStrue to display a bezel around all entries; otherwise, NOfalse to show no bezel around all entries.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

    See Also

    – setBordered:
    isBezeled (NSCell)

  • Sets whether the receiver's entries should display a border around their editable text fields.

    Declaration

    Swift

    func setBordered(_ flag: Bool)

    Objective-C

    - (void)setBordered:(BOOL)flag

    Parameters

    flag

    YEStrue to display a border around all entries; otherwise, NOfalse to show no border around all entries.

    Discussion

    The border is drawn as a thin line around the editable text field. An entry can have a border or a bezel, but not both.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

    See Also

    – setBezeled:
    isBordered (NSCell)

  • Sets the width of all the entries in the receiver.

    Declaration

    Swift

    func setEntryWidth(_ width: CGFloat)

    Objective-C

    - (void)setEntryWidth:(CGFloat)width

    Parameters

    width

    The width of all entries, measured in points in the user coordinate space. This value represents the width of both the title and the text field.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Sets the size of the receiver’s frame size to the specified value.

    Declaration

    Swift

    func setFrameSize(_ newSize: NSSize)

    Objective-C

    - (void)setFrameSize:(NSSize)newSize

    Parameters

    newSize

    The new size of the form.

    Discussion

    The width of NSFormCell objects always match the width of their encompassing NSForm object. The cell width is always changed to match the view regardless of the value returned by autosizesCells.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    Deprecated in OS X v10.10.

  • Sets the spacing between entries

    Declaration

    Swift

    func setInterlineSpacing(_ spacing: CGFloat)

    Objective-C

    - (void)setInterlineSpacing:(CGFloat)spacing

    Parameters

    spacing

    The spacing between entries, measured in points in the user coordinate space.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Sets the alignment for all of the entry titles.

    Declaration

    Swift

    func setTitleAlignment(_ alignment: NSTextAlignment)

    Objective-C

    - (void)setTitleAlignment:(NSTextAlignment)alignment

    Parameters

    alignment

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

    Discussion

    The default alignment is NSRightTextAlignment.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Sets the writing direction for the title of every control embedded in the form.

    Declaration

    Swift

    func setTitleBaseWritingDirection(_ writingDirection: NSWritingDirection)

    Objective-C

    - (void)setTitleBaseWritingDirection:(NSWritingDirection)writingDirection

    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.

    Deprecated in OS X v10.10.

  • Sets the alignment for all of the receiver’s editable text.

    Declaration

    Swift

    func setTextAlignment(_ alignment: NSTextAlignment)

    Objective-C

    - (void)setTextAlignment:(NSTextAlignment)alignment

    Parameters

    alignment

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

    Discussion

    The default alignment is NSLeftTextAlignment.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Sets the writing direction for the text content of every control embedded in the form.

    Declaration

    Swift

    func setTextBaseWritingDirection(_ writingDirection: NSWritingDirection)

    Objective-C

    - (void)setTextBaseWritingDirection:(NSWritingDirection)writingDirection

    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.

    Deprecated in OS X v10.10.

    See Also

    baseWritingDirection (NSControl)

  • Sets the font for all of the entry titles.

    Declaration

    Swift

    func setTitleFont(_ font: NSFont)

    Objective-C

    - (void)setTitleFont:(NSFont *)font

    Parameters

    font

    The font to use for all entry titles.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Sets the font for all of the receiver’s editable text fields

    Declaration

    Swift

    func setTextFont(_ font: NSFont)

    Objective-C

    - (void)setTextFont:(NSFont *)font

    Parameters

    font

    The font to use for all editable text fields.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Returns the index of the entry whose tag is tag.

    Declaration

    Swift

    func indexOfCellWithTag(_ tag: Int) -> Int

    Objective-C

    - (NSInteger)indexOfCellWithTag:(NSInteger)tag

    Parameters

    tag

    The tag of the desired entry.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

    See Also

    tag (NSCell)

  • Returns the index of the selected entry.

    Declaration

    Swift

    func indexOfSelectedItem() -> Int

    Objective-C

    - (NSInteger)indexOfSelectedItem

    Return Value

    The index of the selected entry, or -1 if no entry is selected.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Returns the entry at the specified index.

    Declaration

    Swift

    func cellAtIndex(_ entryIndex: Int) -> AnyObject!

    Objective-C

    - (id)cellAtIndex:(NSInteger)entryIndex

    Parameters

    entryIndex

    The index of the desired entry.

    Return Value

    The form cell object at the specified index.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Displays the entry at the specified index.

    Declaration

    Swift

    func drawCellAtIndex(_ entryIndex: Int)

    Objective-C

    - (void)drawCellAtIndex:(NSInteger)entryIndex

    Parameters

    entryIndex

    The index of the entry to draw.

    Discussion

    Because this method is called automatically whenever a cell needs drawing, you never need to invoke it explicitly. It is included in the API so you can override it if you subclass NSFormCell.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • The preferred width of the form’s cells when using Auto Layout.

    Declaration

    Swift

    func preferredTextFieldWidth() -> CGFloat

    Objective-C

    - (CGFloat)preferredTextFieldWidth

    Return Value

    The field’s width.

    Discussion

    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.

    The default is -1.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.8 and later.

    Deprecated in OS X v10.10.

  • Sets the preferred text field width used by Auto Layout.

    Declaration

    Swift

    func setPreferredTextFieldWidth(_ preferredWidth: CGFloat)

    Objective-C

    - (void)setPreferredTextFieldWidth:(CGFloat)preferredWidth

    Parameters

    preferredWidth

    The preferred width.

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

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

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

    The default is -1.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.8 and later.

    Deprecated in OS X v10.10.

  • Selects the entry at the specified index.

    Declaration

    Swift

    func selectTextAtIndex(_ entryIndex: Int)

    Objective-C

    - (void)selectTextAtIndex:(NSInteger)entryIndex

    Parameters

    entryIndex

    The index of the entry to select. If the specified index is invalid, this method does nothing.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.