【原】ios开发之使用swift3.0画虚线

近期需要在界面中画虚线,想了想没有啥好的办法,于是百度求解,都是用OC写的,完全不考虑我们swift开发者的感受,于是根据OC转了下swift3.0,经测试没啥问题。

        let shapeLayer: CAShapeLayer = CAShapeLayer.init()

        shapeLayer.bounds = self.view.bounds

        shapeLayer.position = self.view.center

        shapeLayer.fillColor = UIColor.clear.cgColor

        shapeLayer.strokeColor = UIColor.init(hexString: “63747F”).cgColor

        shapeLayer.lineJoin = kCALineJoinRound

        shapeLayer.lineDashPattern = [NSNumber.init(value: 3 as Int32),NSNumber.init(value: 2 as Int32)]

        let path: CGMutablePath = CGMutablePath()

        path.move(to: CGPoint.init(x: self.accountTextField.frame.origin.x, y: self.accountTextField.frame.origin.y+self.accountTextField.frame.height))

        path.addLine(to: CGPoint.init(x: self.accountTextField.frame.origin.x+self.accountTextField.frame.width, y: self.accountTextField.frame.origin.y+self.accountTextField.frame.height))

        shapeLayer.path = path

        self.view.layer.addSublayer(shapeLayer)

附上原文参考链接:http://blog.csdn.net/u012976984/article/details/46785597

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注