CAShapeLayer仅在底部绘制虚线

时间:2015-10-11 19:30:46

标签: ios swift uiview cashapelayer

Hello Guys我一直试图使用此代码

UILabel下面绘制虚线
extension UIView{

    func addDashedBorder() {

            self.layoutIfNeeded()
            let color = UIColor.lightGrayColor().CGColor

            let shapeLayer:CAShapeLayer = CAShapeLayer()
            let frameSize = self.frame.size
            let shapeRect = CGRect(x: 0, y: 0, width: frameSize.width, height: 0)

            shapeLayer.bounds = shapeRect
            shapeLayer.position = CGPoint(x: frameSize.width/2, y: frameSize.height)
            shapeLayer.fillColor = UIColor.clearColor().CGColor
            shapeLayer.strokeColor = color
            shapeLayer.lineWidth = 0.50
            shapeLayer.lineJoin = kCALineJoinRound

            shapeLayer.lineDashPattern = [3,2]
            shapeLayer.path = UIBezierPath(roundedRect: CGRectMake(0, shapeRect.height, shapeRect.width, 0), cornerRadius: 0).CGPath

            self.layer.addSublayer(shapeLayer)

    }

}

所以我在这里尝试创建扩展,以便我可以将它用于我的代码中的每个位置。但是这段时间并没有给我一个完美的结果。

enter image description here

有时这段代码检查失败只是检查我使用相同代码但没有得到预期结果的标签中的性别出生日期,有什么建议?

0 个答案:

没有答案
相关问题