将PointF []转换为CGPoint []

时间:2018-05-10 18:10:37

标签: ios xamarin xamarin.ios

CGContext.AddLines ctxt.AddLines (new PointF[] { new PointF (30, 30), new PointF (60, 30), new PointF (40, 40) }); 中的示例代码不能为我编译。

  public void AddStraightLine(PointF start, PointF end)
  {
     var path = new CGPath();

     path.AddLines(new CGPoint[]
     {
        start,
        end
     });
  }

错误是

  

无法从'System.Drawing.PointF []'转换为'CoreGraphics.CGPoint []'

我注意到这有效:

GHCi

1 个答案:

答案 0 :(得分:1)

文档有点过时,您必须将其切换为使用CoreGraphics.CGPoint,这是最新且唯一的重载,而不是System.Drawing.PointF。这是所需切换到iOS Unified API的结果。

从文档移植到iOS的相应统一更改将如下所示:

using (var ctxt = UIGraphics.GetCurrentContext())
{
    var startingPoint = new CGPoint(20, 20);
    ctxt.MoveTo(startingPoint.X, startingPoint.Y);
    ctxt.SetStrokeColor(UIColor.Red.CGColor);
    var sz = new CGSize(2, 2);
    Func<CGPoint, CGPoint> offset = (CGPoint pt) => new CGPoint(pt.X - 1, pt.Y - 1);
    ctxt.AddEllipseInRect(new CGRect(offset(startingPoint), sz));

    ctxt.AddLines(new CGPoint[]
    {
        new CGPoint (30, 30),
        new CGPoint (60, 30),
        new CGPoint (40, 40)
    });

    ctxt.StrokePath();
}