i am creating a custom renderer for Xamarin.Forms Frame control to enable extended functionality like gradient background.
for now i got it to work somehow on iOS but i am working on the android version too.
First i tried to override the SetupLayer method as it is in the default frame renderer see here, and add a sublayer there
The way i got it to work was to override Draw method and add a sublayer to the frame view and set the frame layer background to UIColor.Clear.
The issue that i got is that controls i put inside of frame and also the gradient is somehow faded like there is some layer blending stuff going on. something like .5 opacity.
Any advice how to get the Layer behind (Gradient) fully opaque?
Am i doing it wrong ?
Thanks in advance.
Update : I had removed unnecessary code from sample for not creating confusion, the issue i am facing is understand how layers blending work in iOS, as the top-layers blend with added gradient layer and look more faded than normal frame.
//not working
private void SetupLayer()
{
***
var gl = new CAGradientLayer
{
StartPoint = new CGPoint(0, 0),
EndPoint = new CGPoint(1, 1),
Frame = rect,
Colors = new CGColor[]
{
_gradinetControl.StartColor.ToCGColor(),
_gradinetControl.EndColor.ToCGColor()
},
CornerRadius = _gradinetControl.CornerRadius
};
Layer.BackgroundColor = UIColor.Clear.CGColor;
Layer.InsertSublayer(gl,0);
***
}
*
//working but strange fade blending
public override void Draw(CGRect rect)
{
var gl = new CAGradientLayer
{
StartPoint = new CGPoint(0, 0),
EndPoint = new CGPoint(1, 1),
Frame = rect,
Colors = new CGColor[]
{
_gradinetControl.StartColor.ToCGColor(),
_gradinetControl.EndColor.ToCGColor()
},
CornerRadius = _gradinetControl.CornerRadius
};
NativeView.Layer.BackgroundColor = UIColor.Clear.CGColor;
NativeView.Layer.InsertSublayer(gl,0);
base.Draw(rect);
}