---
title: "withAlphaComponent(_:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uicolor/withalphacomponent(_:)"
---

# withAlphaComponent(_:)

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

## Declaration

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

## Parameters

- `alpha`: The opacity value of the new color object, specified as a value from 0.0 to 1.0. Alpha values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.

## Return Value

Return Value The new UIColor object.

## Discussion

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

## See Also

### Creating a color from another color object

- [init(_:)](uikit/uicolor/init(_:).md)
- [init(ciColor:)](uikit/uicolor/init(cicolor:)-2z057.md)
- [init(cgColor:)](uikit/uicolor/init(cgcolor:)-27r9g.md)
