I'm trying to recreate the gradient background effect from here:
https://forums.xamarin.com/discussion/22440/gradient-as-background-color
But instead of using it as page background I want to use it in a boxView, the problem is that IOS renders the colors into lighter versions, as if it has opacity values under 1 (or similar...)
For the common component I'm extending the boxview class adding it a two Xamarin.Forms.Color properties (StartColor and EndColor):
public class GradientBoxView : BoxView
{
public Xamarin.Forms.Color StartColor { get; set; }
public Xamarin.Forms.Color EndColor { get; set; }
}
The custom renderer class for IOS is this:
public class GradientBoxViewRenderer : BoxRenderer
{
public override void Draw (CGRect rect)
{
base.Draw (rect);
this.Element.Opacity = 1;
GradientBoxView box = (GradientBoxView)this.Element;
CGColor startColor = box.StartColor.ToCGColor();//box.StartColor.AddLuminosity(1).MultiplyAlpha(2).ToCGColor();//
CGColor endColor = box.EndColor.ToCGColor();//box.EndColor.AddLuminosity(1).MultiplyAlpha(2).ToCGColor();//
var gradientLayer = new CAGradientLayer();
//gradientLayer.Opaque = true;
gradientLayer.Frame = rect;
gradientLayer.Colors = new CGColor[] { startColor, endColor };
//NativeView.Opaque = true;
NativeView.Layer.InsertSublayer (gradientLayer, 0);
}
}
Searching in the forum I did find someone having a similar issue with IOS topBar colors and the solution was setting "Opaque" to true and "Translucent" to false, but BoxView doesn't seems to have a Translucent property to play with and the "Opaque" one does nothing (at least I cant tell a difference by commenting/uncommenting the lines of my renderer where I play with it...)
Anyone here with the same issue or with any solution?