如何在Popover的箭头上添加边框?

时间:2019-01-10 18:58:38

标签: ios swift uipopovercontroller

我已经创建了一个类似这样的弹出窗口视图(请注意颜色)。有什么方法可以将边框添加到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

2 个答案:

答案 0 :(得分:1)

您需要创建UIPopoverBackgroundView的子类来进行自定义工程图。然后将popoverBackgroundViewClass上的UIPopoverPresentationController设置为您的子类。

答案 1 :(得分:0)

您可以使用ElegantPopover库来完成它。图书馆将手工绘制边框的一部分。您需要传递边框颜色,宽度和箭头指标的参数。