---
title: "withAlphaComponent(_:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nscolor/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.

## Declaration

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

## Parameters

- `alpha`: The opacity value of the new NSColor object.

## Return Value

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

## Discussion

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

## See Also

### Related Documentation

- [alphaComponent](appkit/nscolor/alphacomponent.md)

### Transforming existing color objects

- [usingColorSpace(_:)](appkit/nscolor/usingcolorspace(_:).md)
- [blended(withFraction:of:)](appkit/nscolor/blended(withfraction:of:).md)
- [highlight(withLevel:)](appkit/nscolor/highlight(withlevel:).md)
- [shadow(withLevel:)](appkit/nscolor/shadow(withlevel:).md)
