NSAppearance Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in OS X v10.9 and later.
Declared in
NSAppearance.h

Overview

An NSAppearance object represents a file that specifies a standard or custom appearance that applies to a subset of UI elements in an app. An app can contain multiple appearance files and—because NSAppearance conforms to NSCoding—you can use Interface Builder to assign UI elements to an appearance.

Typically, you customize a window by using Xcode to create an appearance file that contains the views you want to customize and the custom art that should be applied to them. Xcode transforms the file’s art content into a runtime format that AppKit can draw when the specified views are displayed.

If the art for a specific view can’t be found, AppKit searches for the art in the appearances of the view’s ancestors. A nil appearance means that a view uses the default Aqua appearance; a non-nil appearance means that the view uses an ancestor’s appearance.

When AppKit draws a control, it automatically sets the current appearance on the current thread to the control’s appearance. The current appearance can influence the actual drawing path and the return values you get when you access system fonts and colors. The current appearance also affects the appearance of text and images, such as the text and template images that can be displayed in a toolbar.

Tasks

Creating an Appearance

Getting an Appearance

Getting and Setting the Current Appearance

Class Methods

appearanceNamed:

Returns the NSAppearance object with the specified name.

+ (NSAppearance *)appearanceNamed:(NSString *)name
Parameters
name

The name of a standard or custom appearance. See “Standard Appearances” for standard appearance names.

Return Value

A standard or custom appearance object.

Discussion

When you specify a standard appearance name—such as NSAppearanceNameAqua—this method returns a built-in appearance. If you specify a custom appearance name, this method searches the main bundle for an appearance file that has the specified name.

Availability
  • Available in OS X v10.9 and later.
Declared In
NSAppearance.h

currentAppearance

Returns the NSAppearance object that’s set on the current thread.

+ (NSAppearance *)currentAppearance
Return Value

The appearance object that’s set on the current thread.

Discussion

When a UI element draws on the screen, it automatically sets the appearance that it’s using on the current thread.

Availability
  • Available in OS X v10.9 and later.
Declared In
NSAppearance.h

setCurrentAppearance:

Sets the current appearance to the specified NSAppearance object.

+ (void)setCurrentAppearance:(NSAppearance *)appearance
Parameters
appearance

The NSAppearance object that should be used for the window or view, or nil to specify the default appearance.

Discussion

When you set an appearance on a window, all views in that window—including the window background and controls in both the frame and content areas—use that appearance. By default, AppKit sets the current appearance for standard windows and views during window drawing, so you don't need to use this method unless you want to change the current appearance of a specific window or view.

You can use this method to set the current appearance for an offscreen view to the appearance that will be used when the view is drawn. To do this, use the offscreen view’s effectiveAppearance for the appearance parameter.

Availability
  • Available in OS X v10.9 and later.
Declared In
NSAppearance.h

Instance Methods

initWithAppearanceNamed:bundle:

Creates an NSAppearance object initialized to the specified appearance file in the specified bundle.

- (id)initWithAppearanceNamed:(NSString *)name bundle:(NSBundle *)bundle
Parameters
name

The name of the appearance file to search for, without any path information.

bundle

The bundle in which to search for the appearance file. If bundle is nil, this method searches in the main bundle.

Return Value

An initialized appearance object, or nil if an error occurs.

Availability
  • Available in OS X v10.9 and later.
Declared In
NSAppearance.h

Constants

Standard Appearances

These strings are used to specify standard appearances provided by OS X.

APPKIT_EXTERN NSString *const NSAppearanceNameAqua;
APPKIT_EXTERN NSString *const NSAppearanceNameLightContent;
Constants
NSAppearanceNameAqua

The standard Aqua appearance.

Available in OS X v10.9 and later.

Declared in NSAppearance.h.

NSAppearanceNameLightContent

The standard appearance that can be used by controls in light content areas (not including window-frame areas).

Available in OS X v10.9 and later.

Declared in NSAppearance.h.