Xamarin IOS - 在 2 个 UIButton 之间插入虚线

Xamarin IOS - Insert a dotted line between 2 UIButtons

我正在努力在按钮之间插入虚线,类似于带按钮的 GridView。

IOS 为 Xamarin 提供的 API 中是否有任何预定义的东西可以解决这个问题?

提前致谢

使用 UIView 子类来包含您的线条图,以便您可以应用约束并将其与其他视图对齐。

UIView 子类中,覆盖 Draw 方法:

public override void Draw(CGRect rect)
{
    var path = new UIBezierPath();
    path.MoveTo(new CGPoint(Bounds.Size.Width / 2, 0));
    path.AddLineTo(new CGPoint(Bounds.Size.Width / 2, Bounds.Size.Height));
    path.LineWidth = 6;

    var dashes = new []{ 0 , path.LineWidth * 2 };
    path.SetLineDash(dashes, 0, dashes.Length, 0);
    path.LineCapStyle = CGLineCap.Round;

    (UIColor.White).SetStroke();
    path.Stroke();
}

回复:我使用虚线技术有一段时间了,来自这个 SO Answer

将此 View 与此 SO 的答案相结合,您可以创建: