Beispiel #1
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);
            using (CGContext context = UIGraphics.GetCurrentContext())
            {
                nfloat cellSize = rect.Width / cellCount;
                context.SetLineWidth(1);
                context.SetStrokeColor(UIColor.Gray.CGColor);

                for (int row = 0; row < cellSize; row++)
                {
                    nfloat    top     = row * cellSize;
                    CGPoint[] pointsH = { new CGPoint(0, top), new CGPoint(rect.Width, top) };
                    context.AddLines(pointsH);
                    for (int column = 0; column < cellSize; column++)
                    {
                        nfloat    left    = column * cellSize;
                        CGPoint[] pointsV = { new CGPoint(left, 0), new CGPoint(left, rect.Height) };
                        context.AddLines(pointsV);
                    }
                }

                context.DrawPath(CGPathDrawingMode.FillStroke);
            }
        }
Beispiel #2
0
 public override void Draw(CGRect rect)
 {
     using (CGContext g = UIGraphics.GetCurrentContext())
     {
         g.AddLines(new[] { new CGPoint(Element.TranslationX, Element.TranslationY), new CGPoint(Element.EndX, Element.EndY) });
     }
 }
Beispiel #3
0
            public override void DrawInContext(CGContext ctx)
            {
                base.DrawInContext(ctx);

                ctx.SetLineWidth(1);
                ctx.SetStrokeColor(UIColor.Green.CGColor);
                ctx.AddLines(new[] { new CGPoint(0, Frame.Height * .5f), new CGPoint(Frame.Width, Frame.Height * .5f) });
                ctx.AddLines(new[] { new CGPoint(Frame.Width * .5f, Frame.Height), new CGPoint(Frame.Width * .5f, 0) });
                ctx.DrawPath(CGPathDrawingMode.Stroke);

                UIGraphics.PushContext(ctx);
                ctx.SetFillColor(UIColor.Black.CGColor);
                NSString number = new NSString(string.Format("{0}:{1}", columnIndex, rowIndex));

                number.DrawString(new CGPoint(Frame.Width * .5f - 18, Frame.Height * .5f - 8), UIFont.FromName("Arial", 12));
                UIGraphics.PopContext();
            }
    public override void DrawInContext(CGContext context)
    {
        // Draw lines with a white stroke color
        context.SetRGBStrokeColor(1f, 1f, 1f, 1f);

        // Draw them with a 2.0 stroke width so they are more visible
        context.SetLineWidth(2);

        context.MoveTo(10, 30);
        context.AddLineToPoint(310, 30);
        context.StrokePath();

        // Draw connected sequence of lines
        var points = new PointF [] {
            new PointF(10, 90),
            new PointF(70, 60),
            new PointF(130, 90),
            new PointF(190, 60),
            new PointF(250, 90),
            new PointF(310, 60)
        };

        context.AddLines(points);
        context.StrokePath();

        var segments = new PointF [] {
            new PointF(10, 150),
            new PointF(70, 120),
            new PointF(130, 150),
            new PointF(190, 120),
            new PointF(250, 150),
            new PointF(310, 120),
        };

        // Bulk call to stroke a sequence of line segments

        context.StrokeLineSegments(segments);
    }
	public override void DrawInContext (CGContext context)
	{
		// Draw lines with a white stroke color
		context.SetRGBStrokeColor (1f, 1f, 1f, 1f);

		// Draw them with a 2.0 stroke width so they are more visible
		context.SetLineWidth (2);

		context.MoveTo (10, 30);
		context.AddLineToPoint (310, 30);
		context.StrokePath ();

		// Draw connected sequence of lines
		var points = new PointF [] {
			new PointF (10, 90),
			new PointF (70, 60),
			new PointF (130, 90),
			new PointF (190, 60),
			new PointF (250, 90),
			new PointF (310, 60)
		};
		
		context.AddLines (points);
		context.StrokePath ();

		var segments = new PointF [] {
			new PointF (10, 150),
			new PointF (70, 120),
			new PointF (130, 150),
			new PointF (190, 120),
			new PointF (250, 150),
			new PointF (310, 120),
		};

		// Bulk call to stroke a sequence of line segments

		context.StrokeLineSegments (segments);
	}
Beispiel #6
0
        public override void Draw(RectangleF rect)
        {
            float[] color = Color.CGColor.Components;
            UIGraphics.BeginImageContext(new SizeF(30, 20));
            CGContext ctx = UIGraphics.GetCurrentContext();

            ctx.SetRGBFillColor(color[0], color[1], color[2], 1);
            ctx.SetShadowWithColor(SizeF.Empty, 7f, UIColor.Black.CGColor);

            ctx.AddLines(new[]
            {
                new PointF(15, 5),
                new PointF(25, 25),
                new PointF(5, 25)
            });
            ctx.ClosePath();
            ctx.FillPath();

            UIImage viewImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            var imgframe = new RectangleF((ShowOnRect.X + ((ShowOnRect.Width - 30) / 2)),
                                          ((ShowOnRect.Height / 2) + ShowOnRect.Y), 30, 13);

            var img = new UIImageView(viewImage);

            AddSubview(img);
            img.TranslatesAutoresizingMaskIntoConstraints = false;
            var dict = new NSDictionary("img", img);

            img.Superview.AddConstraints(
                NSLayoutConstraint.FromVisualFormat(string.Format(@"H:|-{0}-[img({1})]", imgframe.X, imgframe.Width),
                                                    NSLayoutFormatOptions.DirectionLeadingToTrailing, null, dict));
            img.Superview.AddConstraints(
                NSLayoutConstraint.FromVisualFormat(string.Format(@"V:|-{0}-[img({1})]", imgframe.Y, imgframe.Height),
                                                    NSLayoutFormatOptions.DirectionLeadingToTrailing, null, dict));


            UIFont font    = UIFont.FromName(FontName, FontSize);
            var    message = new NSAttributedString(Message, font);
            SizeF  size    = message.GetBoundingRect(new SizeF(FieldFrame.Width - (PaddingInErrorPopUp) * 2, 1000),
                                                     NSStringDrawingOptions.UsesLineFragmentOrigin, null).Size;

            size = new SizeF((float)Math.Ceiling(size.Width), (float)Math.Ceiling(size.Height));

            var view = new UIView(RectangleF.Empty);

            InsertSubviewBelow(view, img);
            view.BackgroundColor    = Color;
            view.Layer.CornerRadius = 5f;
            view.Layer.ShadowColor  = UIColor.Black.CGColor;
            view.Layer.ShadowRadius = 5f;
            view.Layer.Opacity      = 1f;
            view.Layer.ShadowOffset = SizeF.Empty;
            view.TranslatesAutoresizingMaskIntoConstraints = false;
            dict = new NSDictionary("view", view);
            view.Superview.AddConstraints(
                NSLayoutConstraint.FromVisualFormat(
                    string.Format(@"H:|-{0}-[view({1})]",
                                  FieldFrame.X + (FieldFrame.Width - (size.Width + (PaddingInErrorPopUp * 2))),
                                  size.Width + (PaddingInErrorPopUp * 2)),
                    NSLayoutFormatOptions.DirectionLeadingToTrailing, null, dict));
            view.Superview.AddConstraints(
                NSLayoutConstraint.FromVisualFormat(
                    string.Format(@"V:|-{0}-[view({1})]", imgframe.Y + imgframe.Height,
                                  size.Height + (PaddingInErrorPopUp * 2)),
                    NSLayoutFormatOptions.DirectionLeadingToTrailing, null, dict));

            var lbl = new UILabel(RectangleF.Empty)
            {
                Font            = font,
                Lines           = 0,
                BackgroundColor = UIColor.Clear,
                Text            = Message,
                TextColor       = FontColor
            };

            view.AddSubview(lbl);

            lbl.TranslatesAutoresizingMaskIntoConstraints = false;
            dict = new NSDictionary("lbl", lbl);
            lbl.Superview.AddConstraints(
                NSLayoutConstraint.FromVisualFormat(
                    string.Format(@"H:|-{0}-[lbl({1})]", PaddingInErrorPopUp, size.Width),
                    NSLayoutFormatOptions.DirectionLeadingToTrailing, null, dict));
            lbl.Superview.AddConstraints(
                NSLayoutConstraint.FromVisualFormat(
                    string.Format(@"V:|-{0}-[lbl({1})]", PaddingInErrorPopUp, size.Height),
                    NSLayoutFormatOptions.DirectionLeadingToTrailing, null, dict));
        }
	public override void DrawInContext (CGContext context)
	{
		// Drawing with a white stroke color
		context.SetStrokeColor (1, 1, 1, 1);
		// And draw with a blue fill color
		context.SetFillColor (0, 0, 1, 1);
		// Draw them with a 2 stroke width so they are a bit more visible.
		context.SetLineWidth (2);

		// Add an ellipse circumscribed in the given rect to the current path, then stroke it
		context.AddEllipseInRect (new CGRect (30, 30, 60, 60));
		context.StrokePath ();

		// Stroke ellipse convenience that is equivalent to AddEllipseInRect(); StrokePath();
		context.StrokeEllipseInRect (new CGRect (30, 120, 60, 60));

		// Fill rect convenience equivalent to AddEllipseInRect(); FillPath();
		context.FillEllipseInRect (new CGRect (30, 210, 60, 60));

		// Stroke 2 seperate arcs
		context.AddArc (150, 60, 30, 0, (float)Math.PI / 2, false);
		context.StrokePath ();
		context.AddArc (150, 60, 30, (float)(3 * Math.PI / 2), (float)Math.PI, true);
		context.StrokePath ();

		// Stroke 2 arcs together going opposite directions.
		context.AddArc (150, 150, 30, 0, (float)Math.PI / 2, false);
		context.AddArc (150, 150, 30, (float)(3 * Math.PI / 2), (float)Math.PI, true);
		context.StrokePath ();

		// Stroke 2 arcs together going the same direction..
		context.AddArc (150, 240, 30, 0, (float)(Math.PI / 2), false);
		context.AddArc (150, 240, 30, (float)Math.PI, (float)(3 * Math.PI / 2), false);
		context.StrokePath ();

		// Stroke an arc using AddArcToPoint
		CGPoint[] p = {
			new CGPoint (210, 30),
			new CGPoint (210, 60),
			new CGPoint (240, 60),
		};
		context.MoveTo (p [0].X, p [0].Y);
		context.AddArcToPoint (p [1].X, p [1].Y, p [2].X, p [2].Y, 30);
		context.StrokePath ();

		// Show the two segments that are used to determine the tangent lines to draw the arc.
		context.SetStrokeColor (1, 0, 0, 1);
		context.AddLines (p);
		context.StrokePath ();

		// As a bonus, we'll combine arcs to create a round rectangle!

		// Drawing with a white stroke color
		context.SetStrokeColor (1, 1, 1, 1);

		// If you were making this as a routine, you would probably accept a rectangle
		// that defines its bounds, and a radius reflecting the "rounded-ness" of the rectangle.
		var rrect = new CGRect (210, 90, 60, 60);
		var radius = 10;
		// NOTE: At this point you may want to verify that your radius is no more than half
		// the width and height of your rectangle, as this technique degenerates for those cases.

		// In order to draw a rounded rectangle, we will take advantage of the fact that
		// context.AddArcToPoint will draw straight lines past the start and end of the arc
		// in order to create the path from the current position and the destination position.

		// In order to create the 4 arcs correctly, we need to know the min, mid and max positions
		// on the x and y lengths of the given rectangle.
		nfloat minx = rrect.X, midx = rrect.X + rrect.Width / 2, maxx = rrect.X + rrect.Width;
		nfloat miny = rrect.Y, midy = rrect.Y + rrect.Height / 2, maxy = rrect.Y + rrect.Height;

		// Next, we will go around the rectangle in the order given by the figure below.
		//       minx    midx    maxx
		// miny    2       3       4
		// midy   1 9              5
		// maxy    8       7       6
		// Which gives us a coincident start and end point, which is incidental to this technique, but still doesn't
		// form a closed path, so we still need to close the path to connect the ends correctly.
		// Thus we start by moving to point 1, then adding arcs through each pair of points that follows.
		// You could use a similar tecgnique to create any shape with rounded corners.

		// Start at 1
		context.MoveTo (minx, midy);
		// Add an arc through 2 to 3
		context.AddArcToPoint (minx, miny, midx, miny, radius);
		// Add an arc through 4 to 5
		context.AddArcToPoint (maxx, miny, maxx, midy, radius);
		// Add an arc through 6 to 7
		context.AddArcToPoint (maxx, maxy, midx, maxy, radius);
		// Add an arc through 8 to 9
		context.AddArcToPoint (minx, maxy, minx, midy, radius);
		// Close the path
		context.ClosePath ();
		// Fill & stroke the path
		context.DrawPath (CGPathDrawingMode.FillStroke);
	}
        private void DrawLines(CGContext context)
        {
            context.SetDefaultLineSettings();

            for (float i = 0; i <= Frame.Height; i += cellHeight)
                context.AddLines(new[] { new PointF(Frame.X, Frame.Y + i), new PointF(Frame.X + Frame.Width, Frame.Y + i) });

            for (float i = 0; i <= Frame.Width; i += cellWidth)
                context.AddLines(new[] { new PointF(Frame.X + i, Frame.Y), new PointF(Frame.X + i, Frame.Y + Frame.Height) });

            context.DrawPath(CGPathDrawingMode.Stroke);
        }
Beispiel #9
0
    public override void DrawInContext(CGContext context)
    {
        // Drawing with a white stroke color
        context.SetRGBStrokeColor(1, 1, 1, 1);
        // And draw with a blue fill color
        context.SetRGBFillColor(0, 0, 1, 1);
        // Draw them with a 2 stroke width so they are a bit more visible.
        context.SetLineWidth(2);

        // Add an ellipse circumscribed in the given rect to the current path, then stroke it
        context.AddEllipseInRect(new RectangleF(30, 30, 60, 60));
        context.StrokePath();

        // Stroke ellipse convenience that is equivalent to AddEllipseInRect(); StrokePath();
        context.StrokeEllipseInRect(new RectangleF(30, 120, 60, 60));

        // Fill rect convenience equivalent to AddEllipseInRect(); FillPath();
        context.FillEllipseInRect(new RectangleF(30, 210, 60, 60));

        // Stroke 2 seperate arcs
        context.AddArc(150, 60, 30, 0, (float)Math.PI / 2, false);
        context.StrokePath();
        context.AddArc(150, 60, 30, (float)(3 * Math.PI / 2), (float)Math.PI, true);
        context.StrokePath();

        // Stroke 2 arcs together going opposite directions.
        context.AddArc(150, 150, 30, 0, (float)Math.PI / 2, false);
        context.AddArc(150, 150, 30, (float)(3 * Math.PI / 2), (float)Math.PI, true);
        context.StrokePath();

        // Stroke 2 arcs together going the same direction..
        context.AddArc(150, 240, 30, 0, (float)(Math.PI / 2), false);
        context.AddArc(150, 240, 30, (float)Math.PI, (float)(3 * Math.PI / 2), false);
        context.StrokePath();

        // Stroke an arc using AddArcToPoint
        PointF [] p =
        {
            new PointF(210, 30),
            new PointF(210, 60),
            new PointF(240, 60),
        };
        context.MoveTo(p[0].X, p[0].Y);
        context.AddArcToPoint(p[1].X, p[1].Y, p[2].X, p[2].Y, 30);
        context.StrokePath();

        // Show the two segments that are used to determine the tangent lines to draw the arc.
        context.SetRGBStrokeColor(1, 0, 0, 1);
        context.AddLines(p);
        context.StrokePath();

        // As a bonus, we'll combine arcs to create a round rectangle!

        // Drawing with a white stroke color
        context.SetRGBStrokeColor(1, 1, 1, 1);

        // If you were making this as a routine, you would probably accept a rectangle
        // that defines its bounds, and a radius reflecting the "rounded-ness" of the rectangle.
        var rrect  = new RectangleF(210, 90, 60, 60);
        var radius = 10;
        // NOTE: At this point you may want to verify that your radius is no more than half
        // the width and height of your rectangle, as this technique degenerates for those cases.

        // In order to draw a rounded rectangle, we will take advantage of the fact that
        // context.AddArcToPoint will draw straight lines past the start and end of the arc
        // in order to create the path from the current position and the destination position.

        // In order to create the 4 arcs correctly, we need to know the min, mid and max positions
        // on the x and y lengths of the given rectangle.
        float minx = rrect.X, midx = rrect.X + rrect.Width / 2, maxx = rrect.X + rrect.Width;
        float miny = rrect.Y, midy = rrect.Y + rrect.Height / 2, maxy = rrect.Y + rrect.Height;

        // Next, we will go around the rectangle in the order given by the figure below.
        //       minx    midx    maxx
        // miny    2       3       4
        // midy   1 9              5
        // maxy    8       7       6
        // Which gives us a coincident start and end point, which is incidental to this technique, but still doesn't
        // form a closed path, so we still need to close the path to connect the ends correctly.
        // Thus we start by moving to point 1, then adding arcs through each pair of points that follows.
        // You could use a similar tecgnique to create any shape with rounded corners.

        // Start at 1
        context.MoveTo(minx, midy);
        // Add an arc through 2 to 3
        context.AddArcToPoint(minx, miny, midx, miny, radius);
        // Add an arc through 4 to 5
        context.AddArcToPoint(maxx, miny, maxx, midy, radius);
        // Add an arc through 6 to 7
        context.AddArcToPoint(maxx, maxy, midx, maxy, radius);
        // Add an arc through 8 to 9
        context.AddArcToPoint(minx, maxy, minx, midy, radius);
        // Close the path
        context.ClosePath();
        // Fill & stroke the path
        context.DrawPath(CGPathDrawingMode.FillStroke);
    }