ios – 如何在最简单的方式画一条线

前端之家收集整理的这篇文章主要介绍了ios – 如何在最简单的方式画一条线前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我相当新的快速Xcode,我正在尝试一个tic tac趾甲游戏.我有一切想法,除了如何画一条线通过三个x或o的.我不知道如何画线.我已经在网上看到了答案,不能弄清楚.有人可以帮忙吗

非常感谢

解决方法

尝试查看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()即可更新.

猜你在找的iOS相关文章