【问题标题】:How to add border to the arrow of the Popover?如何为 Popover 的箭头添加边框?
【发布时间】:2019-01-10 18:58:37
【问题描述】:

我创建了一个类似这样的弹出框视图(注意颜色)。有什么办法可以给 Popover 添加边框?

我尝试使用 UIBezierPath 来创建模式,但它不起作用。还有什么我可以做的吗?

  class IncutoNotifTableArrow: UIView {

func bezierPathArrowCut() -> UIBezierPath {
    let path = UIBezierPath()
    path.move(to: CGPoint(x: 0.0, y: 10.0))
    path.addLine(to: CGPoint(x: self.frame.width - ((UIScreen.main.bounds.width) * 0.24 - 20.0), y: 10.0))
    path.addLine(to: CGPoint(x: self.frame.width - ((UIScreen.main.bounds.width) * 0.24 - 40.0), y: 0.0))
    path.addLine(to: CGPoint(x: self.frame.width - ((UIScreen.main.bounds.width) * 0.24 - 60.0), y: 10.0))
    path.addLine(to: CGPoint(x: self.frame.width, y: 10.0))
    path.addLine(to: CGPoint(x: self.frame.width, y: self.frame.height))
    path.addLine(to: CGPoint(x: 0.0, y: self.frame.height))
    print(path.cgPath)

    path.close()
    return path
}

override func draw(_ rect: CGRect) {
    let path = bezierPathArrowCut()
    UIColor.white.setFill()
    path.fill()
}



}

This is what I'm getting

This is the Expected Result

【问题讨论】:

    标签: ios swift uipopovercontroller


    【解决方案1】:

    您需要创建一个 UIPopoverBackgroundView 的子类来执行您的自定义绘图。然后将UIPopoverPresentationController 上的popoverBackgroundViewClass 设置为您的子类。

    【讨论】:

    • 你能举个例子吗?我尝试了几种方法,但无法自定义边框。
    【解决方案2】:

    您可以使用ElegantPopover 库来完成它。该库将手动绘制边界的一部分。您需要为边框颜色和宽度以及箭头指标传递参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-26
      • 1970-01-01
      • 1970-01-01
      • 2017-04-04
      • 2021-06-17
      • 1970-01-01
      相关资源
      最近更新 更多