What is the correct syntax for this function in Swift?
The following works fine, and colors the background purple:
self.view.backgroundColor = UIColor.purpleColor()
When I chain the colorWithAlphaComponent function, the view shows the correct alpha for a moment, and then changes to an opaque purple that is relatively dark:
self.view.backgroundColor = UIColor.purpleColor().colorWithAlphaComponent(0.5)
Is this the recommended function for adding an alpha value to a UIColor?
Furthermore, why does the intellisense popup say that this function expects a UIColor as a parameter? E.g.,
self.view.backgroundColor = UIColor.colorWithAlphaComponent(<#UIColor#>)
EDIT: The behavior is strange. I am setting the background color on a view controller that is being loaded in a modal. As the modal slides up from the bottom, the alpha is correct. When the modal finishes loading, the background color changes to opaque?!
EDIT 2: The problem was not with the code--both the code above and the suggestion below were properly applying the alpha. The issue is the way that modals are being presented--the underlying view is being removed. See:
Transparent Modal View on Navigation Controller