How to set UIView Frame shape similar to the draw line shape and area in Xamarin.Ios

gdkgdk INMember ✭✭✭
edited December 2016 in Xamarin.iOS


Here my code :

var width = Math.Abs(latestPoint.X - initioalPoint.X) + initioalPoint.X;

var height = Math.Abs(latestPoint.Y - initioalPoint.Y) + initioalPoint.Y;

var padding = 10;

var drawLine = new CAShapeLayer()
 {
  Path = new CGPath(),

  StrokeColor = UIColor.Blue.CGColor,

  LineWidth = 3.0f,

  FillColor = UIColor.Clear.CGColor,

  Frame = new CGRect(5, 5, width + padding - 2, height + padding - 2),

};

drawLine.Path.AddLines(new CGPoint[] { initioalPoint, latestPoint });

var subView = new UIView();

subview.Layer.AddSubLayer(drawLine);

What my requirement is I want to set the subView frame exactly what I mentioned red color mark in image i.e only surrounded with draw line.If I set the frame based upon starting and ending point of draw line it takes huge area i.e in image you can see gray color area, that is what I have set subView frame but I want only red color marked shape frame with same width.

If I try to decrease width, it effects horizontally draw line. If I can decrease the height it effects vertical draw line. Please suggest any idea. Thanks in advance.

Sign In or Register to comment.