Exemplo n.º 1
0
        public override void Draw (CGRect rect)
        {
            base.Draw (rect);

            using (var context = UIGraphics.GetCurrentContext ()) {

                UIBezierPath mainAxis = UIBezierPath.FromRoundedRect ( new CGRect (xAxisMargin, 0.0f, 2.0f, rect.Height), 2.0f);
                UIColor.FromRGB ( 203, 203, 203).SetFill();
                mainAxis.Fill();

                nfloat sepInterval = (nfloat)Math.Floor ((rect.Width - xAxisMargin - xTextMargin)/ 5);
                for (int i = 1; i < 6; i++) {
                    var separatorAxis = new UIBezierPath();
                    separatorAxis.MoveTo (new CGPoint (xAxisMargin + sepInterval * i, 0));
                    separatorAxis.AddLineTo (new CGPoint ( xAxisMargin + sepInterval * i, rect.Height - yAxisMargin));
                    UIColor.FromRGB ( 203, 203, 203).SetStroke();
                    separatorAxis.LineWidth = 1.0f;
                    separatorAxis.SetLineDash ( new nfloat[] {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 CGPoint ( 0.5f, 0.0f);
                    textLayer.AlignmentMode = CATextLayer.AlignmentCenter;
                    textLayer.BackgroundColor = UIColor.Clear.CGColor;
                    textLayer.ForegroundColor = LabelColor.CGColor;

                    CGSize size = ((NSString)"0000 h").StringSize (LabelFont);
                    textLayer.String = "00 h";
                    textLayer.Bounds = new CGRect (0, 0, size.Width, size.Height);
                    textLayer.Position = new CGPoint ( xAxisMargin + sepInterval * i, rect.Height - yAxisMargin + 5.0f);
                    Layer.AddSublayer (textLayer);
                    xAxisText [i - 1] = textLayer;
                }
            }
        }