I\'m trying to programmatically set a background gradient like this in Xamarin iOS:
CGColor[] colors = new CGColor[] { new UIColor(red: 0.05f, green:0.44f, b
Your gradient layer that is assign to the root View
of the ViewController
is being displayed "behind" all the other Views.
By default, views (UILabel, UIButton, etc) do not have a background color set and thus will blend with that background layer, if that is not the effect that you are looking for assign a background to them:
var button = new UIButton(UIButtonType.System);
button.Frame = new CGRect(40, 300, 120, 40);
button.SetTitle("No Background", UIControlState.Normal);
button.TintColor = UIColor.Red;
View.AddSubview(button);
var button2 = new UIButton(UIButtonType.System);
button2.Frame = new CGRect(180, 300, 100, 40);
button2.SetTitle("Background", UIControlState.Normal);
button2.TintColor = UIColor.Red;
button2.BackgroundColor = UIColor.White;
View.AddSubview(button2);
I know I am late for the show but for future reference, I use:
this.View.Layer.InsertSublayer(gradientLayer, 0);
The 0
represents index.