2

Hello Guys i have been trying to Draw the Dotted line below UILabel using this code

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)

    }

}

So here i have been trying to create the extension so i can utilize it to every where in my code. but this doesn't give me the perfect result some time.

enter image description here

sometimes this code failed just check the Gender and Birth date in both the label i have used the same code but not getting the expected result, Any suggestion ?

Lorenzo
  • 3,293
  • 4
  • 29
  • 56
hardikdevios
  • 1,779
  • 14
  • 33

0 Answers0