Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Am I doing this the hard way?

$
0
0

I've got some simple accent lines I want to add to my UI view that I would rather draw than add in as images.

    public class AccentLines : UIView
        {
            public AccentLines ()
            {
            }

            public override void Draw (RectangleF rect)
            {
                base.Draw (rect);

                // get graphics context
                CGContext gctx = UIGraphics.GetCurrentContext ();

                // set up drawing attributes
                gctx.SetLineWidth (1);
                UIColor.FromRGB(51,255,0).SetStroke ();   

                var path = new CGPath ();


                // Top Right


                // Horizontal
                path.AddLines (new PointF[] { 
                    //origin, 
                    new PointF (231,73), 
                    new PointF (291,73) });

                path.CloseSubpath ();

                // add geometry to graphics context and draw it
                gctx.AddPath (path);

                gctx.DrawPath (CGPathDrawingMode.Stroke);

                //Diagonal
                path.AddLines (new PointF[] {
                    new PointF(231,73),
                    new PointF(223,81)
                });

                path.CloseSubpath ();
                gctx.AddPath (path);
                gctx.DrawPath (CGPathDrawingMode.Stroke);


                // Top Left

                //Horizontal
                path.AddLines (new PointF[]{
                    new PointF(49,120),
                    new PointF(214,120)
                });

                //Draw
                path.CloseSubpath();
                gctx.AddPath (path);
                gctx.DrawPath (CGPathDrawingMode.Stroke);

                //Diagonal
                path.AddLines (new PointF[]{
                    new PointF(49,120),
                    new PointF(40,129)
                });

                // Draw
                path.CloseSubpath ();
                gctx.AddPath (path);
                gctx.DrawPath (CGPathDrawingMode.Stroke);

                //Change Color
                UIColor.White.SetStroke();


                // Center Screen


                //Horizontal
                path.AddLines (new PointF[]{
                    new PointF(113,220),
                    new PointF(206,220)
                });

                //Draw
                path.CloseSubpath();
                gctx.AddPath (path);
                gctx.DrawPath (CGPathDrawingMode.Stroke);

                //Diagonal
                path.AddLines (new PointF[]{
                    new PointF(113,220),
                    new PointF(104,229)
                });

                // Draw
                path.CloseSubpath ();
                gctx.AddPath (path);
                gctx.DrawPath (CGPathDrawingMode.Stroke);


                // Bottom Right

                // Bottom Left

            }
        }

In addition to adding in the last two set of lines, I'm going to have to futz around with getting them lined up with the labels that they are underlining. Is there some tool or cheat sheet that I can use, or even a trick, to help me figure out the right coordinates so that I'm not constantly changing numbers, pushing out to my device, changing numbers again, etc.? For example, that third line is supposed to be in the middle of the circle on the screen (which is an image, not going to attempt to draw the hashed circle).

I just feel like there has got to be an easier way.

Thanks.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>