extension UIView {//设置虚线边框 func setDashiedBorder() {let borderLayer = CAShapeLayer()borderLayer.bounds = self.boundsborderLayer.position = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2)borderLayer.path = UIBezierPath(roundedRect: borderLayer.bounds, cornerRadius: 0).CGPathborderLayer.lineWidth = 0.5borderLayer.lineDashPattern = [2, 2]borderLayer.fillColor = UIColor.clearColor().CGColorborderLayer.strokeColor = UIColor(red).CGColorself.layer.addSublayer(borderLayer)}}
如果觉得《为view设置虚线边框》对你有帮助,请点赞、收藏,并留下你的观点哦!