Example #1
0
        public override void Draw(RectangleF rect)
        {
            base.Draw(rect);

            using (var context = UIGraphics.GetCurrentContext()) {
                UIBezierPath mainAxis = UIBezierPath.FromRoundedRect(new RectangleF(xAxisMargin, 0.0f, 2.0f, rect.Height), 2.0f);
                UIColor.FromRGB(203, 203, 203).SetFill();
                mainAxis.Fill();

                float sepInterval = Convert.ToSingle(Math.Floor((rect.Width - xAxisMargin - xTextMargin) / 5));
                for (int i = 1; i < 6; i++)
                {
                    var separatorAxis = new UIBezierPath();
                    separatorAxis.MoveTo(new PointF(xAxisMargin + sepInterval * i, 0));
                    separatorAxis.AddLineTo(new PointF(xAxisMargin + sepInterval * i, rect.Height - yAxisMargin));
                    UIColor.FromRGB(203, 203, 203).SetStroke();
                    separatorAxis.LineWidth = 1.0f;
                    separatorAxis.SetLineDash(new [] { 1.0f, 1.0f }, 1);
                    separatorAxis.Stroke();

                    var textLayer = new CATextLayer();
                    textLayer.ContentsScale = UIScreen.MainScreen.Scale;
                    CGFont font = CGFont.CreateWithFontName(LabelFont.Name);

                    if (font != null)
                    {
                        textLayer.SetFont(font);
                        font.Dispose();
                    }

                    textLayer.FontSize        = LabelFont.PointSize;
                    textLayer.AnchorPoint     = new PointF(0.5f, 0.0f);
                    textLayer.AlignmentMode   = CATextLayer.AlignmentCenter;
                    textLayer.BackgroundColor = UIColor.Clear.CGColor;
                    textLayer.ForegroundColor = LabelColor.CGColor;

                    SizeF size = ((NSString)"0000 h").StringSize(LabelFont);
                    textLayer.String   = "00 h";
                    textLayer.Bounds   = new RectangleF(0, 0, size.Width, size.Height);
                    textLayer.Position = new PointF(xAxisMargin + sepInterval * i, rect.Height - yAxisMargin + 5.0f);
                    Layer.AddSublayer(textLayer);
                    xAxisText [i - 1] = textLayer;
                }
            }
        }
Example #2
0
        private SliceLayer createSliceLayer()
        {
            var pieLayer = new SliceLayer();

            pieLayer.Frame = _pieView.Frame;
            var arcLayer = new CAShapeLayer();

            arcLayer.ZPosition   = 0;
            arcLayer.StrokeColor = null;
            pieLayer.AddSublayer(arcLayer);

            var textLayer = new CATextLayer();

            textLayer.ContentsScale = UIScreen.MainScreen.Scale;
            CGFont font = CGFont.CreateWithFontName(LabelFont.Name);

            if (font != null)
            {
                textLayer.SetFont(font);
                font.Dispose();
            }

            textLayer.FontSize        = LabelFont.PointSize;
            textLayer.AnchorPoint     = new CGPoint(0.5f, 0.5f);
            textLayer.AlignmentMode   = CATextLayer.AlignmentCenter;
            textLayer.BackgroundColor = UIColor.Clear.CGColor;
            textLayer.ForegroundColor = LabelColor.CGColor;

            if (LabelShadowColor != null)
            {
                textLayer.ShadowColor   = LabelShadowColor.CGColor;
                textLayer.ShadowOffset  = CGSize.Empty;
                textLayer.ShadowOpacity = 1.0f;
                textLayer.ShadowRadius  = 2.0f;
            }

            CGSize size = ((NSString)"0").StringSize(LabelFont);

            textLayer.Frame    = new CGRect(new CGPoint(0, 0), size);
            textLayer.Position = new CGPoint(_pieCenter.X + LabelRadius * (nfloat)Math.Cos(0), _pieCenter.Y + LabelRadius * (nfloat)Math.Sin(0));
            pieLayer.AddSublayer(textLayer);
            layerPool.Add(pieLayer);
            return(pieLayer);
        }
Example #3
0
        private BarLayer CreateBarLayer(float barHeight)
        {
            var barLayer = new BarLayer()
            {
                ZPosition   = 0,
                BorderColor = UIColor.White.CGColor,
                AnchorPoint = new PointF(0.0f, 0.5f),
                Frame       = new RectangleF(0, 0, Bounds.Width, barHeight)
            };

            var mainBar = new CALayer();

            mainBar.AnchorPoint     = new PointF(0.0f, 0.0f);
            mainBar.Bounds          = new RectangleF(0, 0, Bounds.Width - xAxisMargin - xTextMargin, barHeight);
            mainBar.Position        = new PointF(xAxisMargin, 0);
            mainBar.BackgroundColor = MainBarColor.CGColor;
            mainBar.SetValueForKeyPath(new NSNumber(minBarScale), new NSString("transform.scale.x"));
            barLayer.AddSublayer(mainBar);

            var secondaryBar = new CALayer();

            secondaryBar.AnchorPoint     = new PointF(0.0f, 0.0f);
            secondaryBar.Bounds          = new RectangleF(0, 0, Bounds.Width - xAxisMargin - xTextMargin, barHeight);
            secondaryBar.Position        = new PointF(xAxisMargin, 0);
            secondaryBar.BackgroundColor = SecondaryBarColor.CGColor;
            secondaryBar.SetValueForKeyPath(new NSNumber(minBarScale), new NSString("transform.scale.x"));
            barLayer.AddSublayer(secondaryBar);

            var emptyBar = new CALayer();

            emptyBar.AnchorPoint     = new PointF(0.0f, 0.0f);
            emptyBar.Bounds          = new RectangleF(0, 0, 2.0f, barHeight);
            emptyBar.Position        = new PointF(xAxisMargin, 0);
            emptyBar.BackgroundColor = UIColor.Gray.CGColor;
            barLayer.AddSublayer(emptyBar);

            CGFont font = CGFont.CreateWithFontName(LabelFont.Name);
            SizeF  size = ((NSString)"00.00:00").StringSize(LabelFont);

            var textLayer = new CATextLayer()
            {
                ContentsScale   = UIScreen.MainScreen.Scale,
                FontSize        = 10.0f,
                AnchorPoint     = new PointF(0.0f, 0.5f),
                AlignmentMode   = CATextLayer.AlignmentLeft,
                BackgroundColor = UIColor.Clear.CGColor,
                ForegroundColor = LabelColor.CGColor
            };

            barLayer.AddSublayer(textLayer);

            var timeTextLayer = new CATextLayer()
            {
                ContentsScale   = UIScreen.MainScreen.Scale,
                FontSize        = 10.0f,
                AnchorPoint     = new PointF(0.0f, 0.5f),
                AlignmentMode   = CATextLayer.AlignmentLeft,
                BackgroundColor = UIColor.Clear.CGColor,
                ForegroundColor = SecondaryBarColor.CGColor
            };

            barLayer.AddSublayer(timeTextLayer);

            if (font != null)
            {
                textLayer.SetFont(font);
                timeTextLayer.SetFont(font);
                font.Dispose();
            }

            CATransaction.DisableActions = true;
            textLayer.Bounds             = new RectangleF(new PointF(0, 0), size);
            textLayer.Position           = mainBar.Position;
            timeTextLayer.Bounds         = new RectangleF(new PointF(0, 0), size);
            timeTextLayer.Position       = new PointF(mainBar.Position.X + 5.0f, mainBar.Position.Y);
            CATransaction.DisableActions = false;

            return(barLayer);
        }