解决方法
尝试查看UIBezierPath它将帮助您很多绘图线.
Documentation这是一个例子:
@H_403_8@override func drawRect(rect: CGRect) {
var aPath = UIBezierPath()
aPath.moveToPoint(CGPoint(x:/*Put starting Location*/,y:/*Put starting Location*/))
aPath.addLineToPoint(CGPoint(x:/*Put Next Location*/,y:/*Put Next Location*/))
//Keep using the method addLineToPoint until you get to the one where about to close the path
aPath.closePath()
//If you want to stroke it with a red color
UIColor.redColor().set()
aPath.stroke()
//If you want to fill it as well
aPath.fill()
}
确保将此代码放在drawRect中.就像上面的例子一样.
如果需要更新图形,只需调用setNeedsDisplay()即可更新.