UIBezierPath只有在UIView的drawRect()方法中使用时才会变成虚线,如下所示:overridefuncdraw(_rect:CGRect){letpath=UIBezierPath()letp0=CGPoint(x:self.bounds.minX,y:self.bounds.midY)path.move(to:p0)letp1=CGPoint(x:self.bounds.maxX,y:self.bounds.midY)path.addLine(to:p1)letdashes:[CGFloat]=[0.0,16.0]path.setLineDash(dashes,