我相当新的快速和
Xcode,我正在尝试一个tic tac趾甲游戏.我有一切想法,除了如何画一条线通过三个x或o的.我不知道如何画线.我已经在网上看到了答案,不能弄清楚.有人可以帮忙吗
非常感谢
解决方法
尝试查看UIBezierPath它将帮助您很多绘图线.
Documentation这是一个例子:
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()即可更新.