title: Swift UIView Opacity Programmatically
body: <p>I'm having quite a hard time messing with UIView's properties to achieve a desired opaque look programmatically that can be easily done through Storyboard and Attributes Inspector.</p>
  
  <p>What I want to re-create (settings from attributes inspector):
  A UIView with a background color of (RGB Sliders: 0, 0, 0) and Opacity Slider set at 75%, with alpha defaulted at 1. So basically a black UIView with the opacity toned down.</p>
  
  <p>What I've tried programmatically:</p>
  
  <pre><code>1)  view.backgroundColor = .black
      view.alpha = 0.75
  
  2)  view.backgroundColor = UIColor.black.withAlphaComponent(0.75)
      view.isOpaque = true
  </code></pre>
  
  <p>Attached is a picture of the UIView selected in Storyboard with the settings for you to see.  If you need any more information, please don't hesitate to let me know.  Much thanks for your help.</p>
  
  <p><img src="https://i.stack.imgur.com/a5Pc1.png" alt="Screenshot of Storyboard + attributes inspector"></p>
  
  <p>UPDATE: Thanks for all your input. The combination of Clever Error's explanation of view layers and Matt's code allowed for me to achieve my desired look.  </p>
  
  <p><a href="https://i.stack.imgur.com/SP7Gg.jpg" rel="noreferrer">Desired UI Look!</a></p>