I was able to draw a dashed box, using the following code:
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
CGRect shapeRect = CGRectMake(0.0f, 0.0f, 200.0f,
Below is the code snippet to draw a Dashed line in UIView (Xamarin iOS)
Note: separatorView is my UIView which i need to show as Dashed
public void ShowDottedLine()
{
var dashedLayer = new CAShapeLayer();
var frameSize = separatorView.Frame.Size;
var shapeRect = new CGRect(0, 0, frameSize.Width, frameSize.Height);
dashedLayer.Bounds = shapeRect;
dashedLayer.Position = new CGPoint(frameSize.Width / 2, frameSize.Height / 2);
dashedLayer.FillColor = UIColor.Clear.CGColor;
dashedLayer.StrokeColor = ColorUtils.ColorWithHex(ColorConstants.DarkBlue).CGColor;
dashedLayer.LineWidth = 2;
dashedLayer.LineJoin = CAShapeLayer.JoinRound;
NSNumber[] patternArray = {5,5};
dashedLayer.LineDashPattern = Array;
var path = new CGPath();
path.MoveToPoint(CGPoint.Empty);
path.AddLineToPoint(new CGPoint(frameSize.Width, 0));
dashedLayer.Path = path;
separatorView.Layer.AddSublayer(dashedLayer);
}