override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let line = CAShapeLayer()
let linePath = UIBezierPath()
linePath.move(to: CGPoint(x: 10, y: 10))
linePath.addLine(to: CGPoint(x: 100, y: 100))
line.path = linePath.cgPath
line.strokeColor = UIColor.red.cgColor
line.lineWidth = 2
line.lineJoin = kCALineJoinRound
self.view.layer.addSublayer(line)
}
结果 效果图