I am fairly new to swift and Xcode and I am trying to make a tic tac toe game. I have everything figured out except how to draw a line through the three x\'s or o\'s. I have
Swift 3.1, inside a UIView:
public override func draw(_ rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
context!.setLineWidth(2.0)
context!.setStrokeColor(UIColor.red.cgColor)
context?.move(to: CGPoint(x: 0, y: self.frame.size.height))
context?.addLine(to: CGPoint(x: self.frame.size.width, y: 0))
context!.strokePath()
}
If you want to add a line to a UIViewController, just add a UIView with this function as a subview to the UIViewController, ei:
let line = LineView(CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height))
self.view.addSubview(line)