Mac Developer Library

Developer

AppKit Framework Reference NSShadow Class Reference

Options
Deployment Target:

On This Page
Language:

NSShadow

An NSShadow object encapsulates the attributes used to create a drop shadow during drawing operations.

Shadows are always drawn in the default user coordinate space, regardless of any transformations applied to that space. This means that rotations, translations and other transformations of the current transformation matrix (the CTM) do not affect the resulting shadow. Another way to think about this is that changes to the CTM do not move or change the apparent position of the shadow’s light source.

There are two positional parameters for a shadow: an x-offset and a y-offset. These values are expressed using a single size data type (CGSize on iOS, NSSize on OS X) and using the units of the default user coordinate space. Positive values for these offsets extend up and to the right.

In addition to its positional parameters, a shadow also contains a blur radius, which specifies how much a drawn object's image mask is blurred before it is composited onto the destination. A value of 0 means there is no blur. Larger values give correspondingly larger amounts of blurring.

An NSShadow object may be used in one of two ways. First, it may be set, like a color or a font, in which case its attributes are applied to all content drawn thereafter—or at least until another shadow is applied or a previous graphics state is restored. Second, it may be used as the value for the NSShadowAttributeName text attribute, in which case it is applied to the glyphs corresponding to the characters bearing this attribute.

Inheritance


Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.3 and later.
  • Returns an NSShadow object initialized with default values.

    Declaration

    Swift

    init()

    Objective-C

    - (instancetype)init

    Return Value

    An NSShadow object initialized with 0 as its offset, 0 as its blur radius, and the default color as its color. The returned object may be different from the original receiver.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • The offset values of the shadow.

    Declaration

    Swift

    var shadowOffset: NSSize

    Objective-C

    @property NSSize shadowOffset

    Discussion

    This property contains the horizontal and vertical offset values, specified using the width and height fields of the CGSize data type. These offsets are measured using the default user coordinate space and are not affected by custom transformations. This means that positive values always extend down and to the right from the user's perspective.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the offset values for the receiver.

    Declaration

    Swift

    var shadowOffset: NSSize

    Objective-C

    @property NSSize shadowOffset

    Return Value

    The horizontal and vertical offset values, specified using the width and height fields of the NSSize data type. These offsets are measured using the default user coordinate space and are not affected by custom transformations. This means that positive values always extend up and to the right from the user's perspective.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets the offset values for the receiver.

    Declaration

    Swift

    var shadowOffset: NSSize

    Objective-C

    @property NSSize shadowOffset

    Parameters

    offset

    The horizontal and vertical offset values, specified using the width and height fields of the NSSize data type. These offsets are measured using the default user coordinate space and are not affected by custom transformations. This means that positive values always extend up and to the right from the user's perspective.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • The blur radius of the shadow.

    Declaration

    Swift

    var shadowBlurRadius: CGFloat

    Objective-C

    @property CGFloat shadowBlurRadius

    Discussion

    This property contains the blur radius, as measured in the default user coordinate space. A value of 0 indicates no blur, while larger values produce correspondingly larger blurring. The default value is 0.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the blur radius of the receiver.

    Declaration

    Swift

    var shadowBlurRadius: CGFloat

    Objective-C

    @property CGFloat shadowBlurRadius

    Return Value

    The blur radius, as measured in the default user coordinate space. A value of 0 indicates no blur, while larger values produce correspondingly larger blurring. The default value is 0.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets the blur radius of the receiver.

    Declaration

    Swift

    var shadowBlurRadius: CGFloat

    Objective-C

    @property CGFloat shadowBlurRadius

    Parameters

    val

    The blur radius, as measured in the default user coordinate space. A value of 0 indicates no blur, while larger values produce correspondingly larger blurring. This value must not be negative.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • The color of the shadow.

    Declaration

    Swift

    @NSCopying var shadowColor: NSColor?

    Objective-C

    @property(copy) NSColor *shadowColor

    Discussion

    The default shadow color is black with an alpha of 1/3. If you set this property to nil, the shadow is not drawn.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the color for the receiver.

    Declaration

    Swift

    @NSCopying var shadowColor: NSColor?

    Objective-C

    @property(copy) NSColor *shadowColor

    Return Value

    The current shadow color. A nil shadow color indicates the shadow is not to be drawn. The default shadow color is black with an alpha of 1/3.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets the shadow color for the receiver.

    Declaration

    Swift

    @NSCopying var shadowColor: NSColor?

    Objective-C

    @property(copy) NSColor *shadowColor

    Parameters

    color

    The shadow color, which must be convertible to an RGBA color. Specify nil if you do not want the shadow to be drawn. Your color may contain alpha information.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    See Also

    – shadowColor

  • Sets the shadow of subsequent drawing operations to the shadow represented by the receiver.

    Declaration

    Swift

    func set()

    Objective-C

    - (void)set

    Discussion

    The shadow attributes of the receiver are used until another shadow is set or until the graphics state is restored.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.