title: colorWithAlphaComponent example in Swift
body: <p>What is the correct syntax for this function in Swift?</p>
  
  <p>The following works fine, and colors the background purple:</p>
  
  <pre><code> self.view.backgroundColor = UIColor.purpleColor()
  </code></pre>
  
  <p>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:</p>
  
  <pre><code> self.view.backgroundColor = UIColor.purpleColor().colorWithAlphaComponent(0.5)
  </code></pre>
  
  <p>Is this the recommended function for adding an alpha value to a UIColor?</p>
  
  <p>Furthermore, why does the intellisense popup say that this function expects a UIColor as a parameter? E.g.,</p>
  
  <pre><code>   self.view.backgroundColor = UIColor.colorWithAlphaComponent(&lt;#UIColor#&gt;)
  </code></pre>
  
  <p>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?!</p>
  
  <p>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:<br>
  <a href="https://stackoverflow.com/questions/849458/transparent-modal-view-on-navigation-controller">Transparent Modal View on Navigation Controller</a></p>