NSTabView Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in OS X v10.0 and later.
Companion guide
Declared in
NSTabView.h
Related sample code

Overview

An NSTabView object provides a convenient way to present information in multiple pages. The view contains a row of tabs that give the appearance of folder tabs, as shown in the following figure. The user selects the desired page by clicking the appropriate tab or using the arrow keys to move between pages. Each page displays a view hierarchy provided by your application.

Art/tabview.gif

Tasks

Adding and Removing Tabs

Accessing Tabs

Selecting a Tab

Modifying the Font

Modifying the Tab Type

Modifying Controls Tint

Manipulating the Background

Determining the Size

Truncating Tab Labels

Assigning a Delegate

Event Handling

Instance Methods

addTabViewItem:

Adds the tab item specified by tabViewItem.

- (void)addTabViewItem:(NSTabViewItem *)tabViewItem
Parameters
tabViewItem

The tab view item to be added.

Discussion

The item is added at the end of the array of tab items, so the new tab appears on the right side of the view. If the delegate supports it, invokes the delegate’s tabViewDidChangeNumberOfTabViewItems: method.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

allowsTruncatedLabels

Returns whether if the receiver allows truncating for labels that don’t fit on a tab.

- (BOOL)allowsTruncatedLabels
Return Value

YES if the receiver allows truncating for labels that don’t fit on a tab, otherwise NO.

Discussion

The default is NO.

When truncating is allowed, the tab view inserts an ellipsis, if necessary, to fit a label in the tab.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

contentRect

Returns the rectangle describing the content area of the receiver.

- (NSRect)contentRect
Return Value

Returns the rectangle describing the content area of the receiver.

Discussion

This area does not include the space required for the receiver’s tabs or borders (if any).

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

controlSize

Returns the size of the receiver.

- (NSControlSize)controlSize
Return Value

Valid return values are described inControl Sizes in NSCell Class Reference.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

controlTint

Returns the receiver’s control tint.

- (NSControlTint)controlTint
Return Value

The tab view’s control tint. See NSControlTint for the supported values.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

delegate

Returns the receiver’s delegate.

- (id < NSTabViewDelegate >)delegate
Return Value

The object’s delegate.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

drawsBackground

Returns whether if the receiver draws a background color when the tab view type is NSNoTabsNoBorder.

- (BOOL)drawsBackground
Return Value

YES if the receiver draws a background color when the tab view type is NSNoTabsNoBorder, otherwise NO.

Discussion

If the receiver uses bezeled edges or a line border, the appropriate background color for that border is used.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

font

Returns the font for tab label text.

- (NSFont *)font
Return Value

Returns the tab view label font.

Availability
  • Available in OS X v10.0 and later.
See Also
Declared In
NSTabView.h

indexOfTabViewItem:

Returns the index of the specified item in the tab view.

- (NSInteger)indexOfTabViewItem:(NSTabViewItem *)tabViewItem
Parameters
tabViewItem

The tab view item.

Return Value

The zero-based index of tabViewItem, or [NSNotFound] if the item is not found.

Discussion

The returned index is zero-based.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

indexOfTabViewItemWithIdentifier:

Returns the index of the item that matches the specified identifier. identifier, or NSNotFound if the item is not found.

- (NSInteger)indexOfTabViewItemWithIdentifier:(id)identifier
Parameters
identifier

The identifier of a tab view item.

Return Value

The zero-based index of the tab view item corresponding to identifier, or [NSNotFound] if the item is not found.

Discussion

The returned index is zero-based.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

insertTabViewItem:atIndex:

Inserts tabViewItem into the receiver’s array of tab view items at index.

- (void)insertTabViewItem:(NSTabViewItem *)tabViewItem atIndex:(NSInteger)index
Parameters
tabViewItem

The tab view item to be added.

index

The index at which to insert the tab view item. The index parameter is zero-based.

Discussion

If there is a delegate and the delegate supports it, sends the delegate the tabViewDidChangeNumberOfTabViewItems: message.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

minimumSize

Returns the minimum size necessary for the receiver to display tabs in a useful way.

- (NSSize)minimumSize
Return Value

The minimum size necessary for the receiver to display tabs in a useful way.

Discussion

You can use the value returned by this method to limit how much a user can resize a tab view.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

numberOfTabViewItems

Returns the number of items in the receiver’s array of tab view items.

- (NSInteger)numberOfTabViewItems
Return Value

The number of items in the tab view.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

removeTabViewItem:

Removes the item specified by tabViewItem from the receiver’s array of tab view items.

- (void)removeTabViewItem:(NSTabViewItem *)tabViewItem
Parameters
tabViewItem

The tab view item to be removed.

Discussion

If there is a delegate and the delegate supports it, sends the delegate the tabViewDidChangeNumberOfTabViewItems: message.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

selectedTabViewItem

Returns the tab view item for the currently selected tab

- (NSTabViewItem *)selectedTabViewItem
Return Value

The currently selected tab view item, or nil if no item is selected.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

selectFirstTabViewItem:

This action method selects the first tab view item.

- (void)selectFirstTabViewItem:(id)sender
Parameters
sender

Typically the object that sent invoked the message.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

selectLastTabViewItem:

This action method selects the last tab view item.

- (void)selectLastTabViewItem:(id)sender
Parameters
sender

Typically the object that sent invoked the message.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

selectNextTabViewItem:

This action method selects the next tab view item in the sequence.

- (void)selectNextTabViewItem:(id)sender
Parameters
sender

Typically the object that sent invoked the message.

Discussion

If the currently visible item is the last item in the sequence, this method does nothing, and the last page remains displayed.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

selectPreviousTabViewItem:

This action method selects the previous tab view item in the sequence.

- (void)selectPreviousTabViewItem:(id)sender
Parameters
sender

Typically the object that sent invoked the message.

Discussion

If the currently visible item is the first item in the sequence, this method does nothing, and the first page remains displayed.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

selectTabViewItem:

Selects the specified tab view item.

- (void)selectTabViewItem:(NSTabViewItem *)tabViewItem
Parameters
tabViewItem

The tab item to select.

Discussion

If there is a delegate and the delegate supports it, sends the delegate the tabView:shouldSelectTabViewItem: message.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

selectTabViewItemAtIndex:

Selects the tab view item specified by index.

- (void)selectTabViewItemAtIndex:(NSInteger)index
Parameters
index

The index of the tab item to selected.

Discussion

The index parameter is base 0. If there is a delegate and the delegate supports it, sends the delegate the tabView:shouldSelectTabViewItem: message.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSTabView.h

selectTabViewItemWithIdentifier:

Selects the tab view item specified by identifier.

- (void)selectTabViewItemWithIdentifier:(id)identifier
Parameters
identifier

The identifier of the tab item to select.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

setAllowsTruncatedLabels:

Sets whether the receiver allows truncating for names that don’t fit on a tab.

- (void)setAllowsTruncatedLabels:(BOOL)allowTruncatedLabels
Parameters
allowTruncatedLabels

YES if the receiver allows truncating for labels that don’t fit on a tab, otherwise NO.

Discussion

The default is NO.

When truncating is allowed, the tab view inserts an ellipsis, if necessary, to fit a label in the tab.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

setControlSize:

Sets the size of the receiver to controlSize.

- (void)setControlSize:(NSControlSize)controlSize
Parameters
controlSize

The size of the receiver. Valid values are described in Control Sizes in NSCell Class Reference

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

setControlTint:

Sets the receiver’s control tint to controlTint.

- (void)setControlTint:(NSControlTint)controlTint
Parameters
controlTint

The tab view’s control tint. See NSControlTint for the supported values.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

setDelegate:

Sets the receiver’s delegate.

- (void)setDelegate:(id < NSTabViewDelegate >)anObject
Parameters
anObject

The delegate object. It must conform to the NSTabViewDelegate protocol.

Availability
  • Available in OS X v10.0 and later.
See Also
Declared In
NSTabView.h

setDrawsBackground:

Sets whether a background is drawn when the view type is NSNoTabsNoBorder to flag.

- (void)setDrawsBackground:(BOOL)flag
Parameters
flag

YES if the background should be drawn, otherwise NO.

Discussion

If the receiver has a bezeled border or a line border, the appropriate background for that border is used.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

setFont:

Sets the font for tab label text to font.

- (void)setFont:(NSFont *)font
Parameters
font

The font to use as the tab view label font.

Discussion

Tab height is adjusted automatically to accommodate a new font size. If the view allows truncating, tab labels are truncated as needed.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

setTabViewType:

Sets the tab type to tabViewType.

- (void)setTabViewType:(NSTabViewType)tabViewType
Parameters
tabViewType

The tab type to display the tabs. The supported values are listed in NSTabViewType

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

tabViewItemAtIndex:

Returns the tab view item at index in the tab view’s array of items.

- (NSTabViewItem *)tabViewItemAtIndex:(NSInteger)index
Parameters
index

The index at which to insert the tab view item. The index parameter is zero-based.

Return Value

The tab view item at the specified index.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

tabViewItemAtPoint:

Returns the tab view item at the specified point.

- (NSTabViewItem *)tabViewItemAtPoint:(NSPoint)point
Parameters
point

The hit point.

Return Value

The tab view item under the hit point, or nil if no tab view item is under that location.

Discussion

You can use this method to find a tab view item based on a user’s mouse click.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

tabViewItems

Returns the receiver’s array of tab view items.

- (NSArray *)tabViewItems
Return Value

An array of tab view items.

Discussion

A tab view keeps an array containing one tab view item for each tab in the view.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

tabViewType

Returns the tab type for the receiver.

- (NSTabViewType)tabViewType
Return Value

The tab type to display the tabs. The supported values are listed in NSTabViewType

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

takeSelectedTabViewItemFromSender:

Sets the selected tab view item to the selected item obtained from the sender.

- (void)takeSelectedTabViewItemFromSender:(id)sender
Parameters
sender

Typically the object that sent invoked the message.

Discussion

If sender responds to the indexOfSelectedItem method, this method invokes that method and selects the tab view item at the specified index.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTabView.h

Constants

NSTabViewType

These constants specify the tab view’s type as used by tabViewType and setTabViewType:.

enum {
   NSTopTabsBezelBorder     = 0,
   NSLeftTabsBezelBorder    = 1,
   NSBottomTabsBezelBorder  = 2,
   NSRightTabsBezelBorder   = 3,
   NSNoTabsBezelBorder      = 4,
   NSNoTabsLineBorder       = 5,
   NSNoTabsNoBorder         = 6
};
typedef NSUInteger NSTabViewType;
Constants
NSTopTabsBezelBorder

The view includes tabs on the top of the view and has a bezeled border (the default).

Available in OS X v10.0 and later.

Declared in NSTabView.h.

NSNoTabsBezelBorder

The view does not include tabs and has a bezeled border.

Available in OS X v10.0 and later.

Declared in NSTabView.h.

NSNoTabsLineBorder

The view does not include tabs and has a lined border.

Available in OS X v10.0 and later.

Declared in NSTabView.h.

NSNoTabsNoBorder

The view does not include tabs and has no border.

Available in OS X v10.0 and later.

Declared in NSTabView.h.

NSBottomTabsBezelBorder

Tabs are on the bottom of the view with a bezeled border.

Available in OS X v10.0 and later.

Declared in NSTabView.h.

NSLeftTabsBezelBorder

Tabs are on the left of the view with a bezeled border.

Available in OS X v10.0 and later.

Declared in NSTabView.h.

NSRightTabsBezelBorder

Tabs are on the right of the view with a bezeled border.

Available in OS X v10.0 and later.

Declared in NSTabView.h.

NSAppKitVersionNumberWithDirectionalTabs

This constant specifies the minimum version of the Application Kit that supports directional tabs.

#define NSAppKitVersionNumberWithDirectionalTabs 631.0
Constants
NSAppKitVersionNumberWithDirectionalTabs

The specific version of the AppKit framework that introduced support for directional tab items. Developers should not need to use this constant unless they are writing applications for OS X v10.1 and earlier.

Available in OS X v10.2 and later.

Declared in NSTabView.h.