1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| class ViewController: UIViewController { @IBOutlet weak var targetView: UIView! override func viewDidLoad() { super.viewDidLoad()
let shapeLayer = CAShapeLayer() shapeLayer.strokeColor = UIColor.red.cgColor shapeLayer.fillColor = nil shapeLayer.lineDashPattern = [3, 2, 6, 4] shapeLayer.frame = targetView.bounds shapeLayer.lineWidth = 0.5 shapeLayer.lineCap = .square shapeLayer.path = UIBezierPath(rect: targetView.bounds).cgPath targetView.layer.addSublayer(shapeLayer) } }
|