protected override void OnElementChanged(ElementChangedEventArgs <Button> e) { base.OnElementChanged(e); if (e.OldElement == null) { caller = e.NewElement as GradientButton; gradient = new CAGradientLayer(); gradient.Frame = Control.Bounds; gradient.CornerRadius = Control.Layer.CornerRadius = caller.CornerRadius; gradient.Colors = new CGColor[] { caller.StartColor.ToCGColor(), caller.EndColor.ToCGColor(), }; if (caller.ShadowColor != null) { Control.Layer.ShadowRadius = (nfloat)caller.ShadowRadius; Control.Layer.ShadowColor = caller.ShadowColor.ToCGColor(); Control.Layer.ShadowOffset = new CGSize(0.0f, caller.ShadowOffset); Control.Layer.ShadowOpacity = caller.ShadowOpacity; Control.Layer.MasksToBounds = false; } Control.SetTitleColor(caller.DisabledTextColor.ToUIColor(), UIControlState.Disabled); //caLayer = Control?.Layer.Sublayers.LastOrDefault(); //Control?.Layer.InsertSublayerBelow(gradient, caLayer); Control?.Layer.InsertSublayer(gradient, 0); } }
protected override void OnElementChanged(ElementChangedEventArgs <Button> e) { base.OnElementChanged(e); if (Control != null) { caller = e.NewElement as GradientButton; var gradient = new GradientDrawable(GradientDrawable.Orientation.TopBottom, new[] { caller.StartColor.ToAndroid().ToArgb(), caller.EndColor.ToAndroid().ToArgb() }); gradient.SetCornerRadius(caller.CornerRadius); SetButtonDisableState(); Control.SetBackground(gradient); } }