title: Xamarin - Gradient background
body: <p>I'm trying to programmatically set a background gradient like this in Xamarin iOS:</p>
  
  <pre><code>CGColor[] colors = new CGColor[] { new UIColor(red: 0.05f, green:0.44f, blue:0.73f, alpha:1.0f).CGColor,
                  new UIColor(red: 45/255, green: 128 / 255, blue: 153 / 255, alpha: 0.01f ).CGColor};
              CAGradientLayer gradientLayer = new CAGradientLayer();
              gradientLayer.Frame = this.View.Bounds;
              gradientLayer.Colors = colors;
              this.View.Layer.AddSublayer(gradientLayer);
  </code></pre>
  
  <p>And it works, but I have form elements on the screen (labels, buttons, etc) and this is causing all of them to appear faded, as if the layer appears directly <em>on top</em> of the elements. I think this is what the code is doing - it's rendering the entire page, and then adding the layer with opacity on top of the screen (I want it behind it instead).</p>
  
  <p>What I'd like, instead, is to have the background set as gradient, but any elements I add will not be faded and try to match the background colors.</p>
  
  <p>I tried adding a view on top of the standard view, and setting the alpha to 1, background to white, but that didn't seem to help (suggesting my theory that programmatically it's adding a layer on top of everything after it's rendered).</p>
  
  <p>What am I doing wrong?
   Thanks!</p>