<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSColor/withAlphaComponent(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSColor(im)colorWithAlphaComponent:"
  },
  "title" : "withAlphaComponent(_:)"
}
-->

# withAlphaComponent(_:)

Creates a new color object that has the same color space and component values as the current color object, but the specified alpha component.

```
func withAlphaComponent(_ alpha: CGFloat) -> NSColor
```

## Parameters

`alpha`

The opacity value of the new `NSColor` object.

## Return Value

The new `NSColor` object. If the receiver’s color space doesn’t include an alpha component, the receiver is returned.

## Discussion

A subclass with explicit opacity components should override this method to return a color with the specified alpha.

## See Also

[`alphaComponent`](/documentation/AppKit/NSColor/alphaComponent)

The alpha (opacity) component value of the color.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)