コード例 #1
0
        private UIImage GetGradientImage(nfloat width, CGSize size, CGColor[] colors)
        {
            var gradientLayer = new CAGradientLayer();

            gradientLayer.Frame         = new CGRect(0, 0, width, size.Height);
            gradientLayer.CornerRadius  = gradientLayer.Frame.Height / 2;
            gradientLayer.MasksToBounds = true;
            gradientLayer.Colors        = colors;
            gradientLayer.StartPoint    = new CGPoint(x: 0.0, y: 0.5);
            gradientLayer.EndPoint      = new CGPoint(x: 1.0, y: 0.5);

            if (control.HasSegment)
            {
                var segmentDelay = (size.Width - 10) / (Element.Maximum / control.Interval);

                for (int i = 0; i <= Element.Maximum / control.Interval; i++)
                {
                    var segmentLayer = new CALayer();
                    var myImage      = i * control.Interval < Control.Value ? new UIImage(control.MaxIntervaImageSource) : new UIImage(control.MinIntervaImageSource);
                    segmentLayer.Contents = myImage.CGImage;
                    segmentLayer.Frame    = new CGRect(i == 0 ? 10 : segmentDelay * i, (size.Height - 5) / 2, 5, 5);
                    gradientLayer.AddSublayer(segmentLayer);
                }
            }

            UIGraphics.BeginImageContextWithOptions(size, gradientLayer.Opaque, 0.0f);
            var context = UIGraphics.GetCurrentContext();

            gradientLayer.RenderInContext(context);
            var image = UIGraphics.GetImageFromCurrentImageContext().CreateResizableImage(new UIEdgeInsets(top: 0, left: size.Height, bottom: 0, right: size.Height));

            UIGraphics.EndImageContext();
            return(image);
        }
コード例 #2
0
 protected override void OnElementChanged(VisualElementChangedEventArgs e)
 {
     base.OnElementChanged(e);
     if (null != this.Element)
     {
         var page          = e.NewElement as GradientContentPage;
         var gradientLayer = new CAGradientLayer();
         gradientLayer.Frame      = View.Bounds;
         gradientLayer.StartPoint = new CGPoint(0, 0.5);
         gradientLayer.EndPoint   = new CGPoint(1.0, 0.5);
         gradientLayer.Colors     = new CGColor[] { page.StartColor.ToCGColor(), page.EndColor.ToCGColor() };
         var textureColor = UIColor.FromPatternImage(UIImage.FromFile("bg-pattern.png"));
         var back         = new CALayer {
             Frame = View.Bounds
         };
         back.BackgroundColor = textureColor.CGColor;
         gradientLayer.AddSublayer(back);
         View.Layer.InsertSublayer(gradientLayer, 0);
     }
 }
コード例 #3
0
ファイル: LayerHelper.cs プロジェクト: GrimmRanger/FGUtils
        public static CAGradientLayer StoresGrayGradient(RectangleF frame)
        {
            CAGradientLayer backgroundLayer = new CAGradientLayer();
            backgroundLayer.Frame = new RectangleF(0, 0, frame.Width, frame.Height);
            backgroundLayer.Colors =  new MonoTouch.CoreGraphics.CGColor[]
            {
                UIColor.FromRGBA(65, 75, 73, 255).CGColor,
                UIColor.FromRGBA(40, 46, 45, 255).CGColor
            };

            CALayer topEdge = new CALayer();
            topEdge.Frame = new RectangleF(0, 0, frame.Width, 1.5f);
            topEdge.BackgroundColor = UIColor.FromRGBA(90, 99, 97, 255).CGColor;
            backgroundLayer.AddSublayer(topEdge);

            return backgroundLayer;
        }