public override void Draw(CGRect rect) { CAGradientLayer gradient = new CAGradientLayer(); gradient.Frame = NativeView.Bounds; gradient.NeedsDisplayOnBoundsChange = true; gradient.MasksToBounds = true; gradient.Colors = new CGColor[] { StartColor.ToCGColor(), EndColor.ToCGColor() }; NativeView.Layer.InsertSublayer(gradient, 0); base.Draw(rect); }
private void SetGradientBackground() { if (NavigationController != null) { var gradientLayer = new CAGradientLayer(); gradientLayer.Bounds = NavigationController.NavigationBar.Bounds; gradientLayer.Colors = new CGColor[] { StartColor.ToCGColor(), EndColor.ToCGColor() }; gradientLayer.StartPoint = new CGPoint(0.0, 0.5); gradientLayer.EndPoint = new CGPoint(1.0, 0.5); UIGraphics.BeginImageContext(gradientLayer.Bounds.Size); gradientLayer.RenderInContext(UIGraphics.GetCurrentContext()); UIImage image = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); NavigationController.NavigationBar.SetBackgroundImage(image, UIBarMetrics.Default); } }