Esempio n. 1
0
        public override void DrawRect(RectangleF dirtyRect)
        {
            var height = base.Bounds.Height;
            var calcValue = base.Bounds.Width * (Value * 0.01f);

            var context = NSGraphicsContext.CurrentContext.GraphicsPort;
            context.SetStrokeColor("#999999".ToCGColor());
            context.SetLineWidth (1.0F);

            context.StrokeRect(new RectangleF(0, 0, base.Bounds.Width, height));

            context.SetFillColor("#999999".ToCGColor());
            context.FillRect(new RectangleF(0, 0, base.Bounds.Width, height));

            context.SetFillColor(BackgroundColor.ToCGColor());
            context.FillRect(new RectangleF(0, 0, calcValue, height));

            var attrStr = "{0}".ToFormat(Label).CreateString("#ffffff".ToNSColor(), Font);

            var storage   = new NSTextStorage();
            storage.SetString(attrStr);

            var layout    = new NSLayoutManager();
            var container = new NSTextContainer();

            layout.AddTextContainer(container);
            storage.AddLayoutManager(layout);

            // Get size
            //			var size = layout.GetUsedRectForTextContainer (container).Size;
            //			var width = size.Width / 2.0f;
            var width = (base.Bounds.Width / 2.0f) - (TextOffset.X);

            storage.DrawString(new PointF(width, TextOffset.Y));
        }