I'm trying to make a simple app. To do so, in part, I'm trying to use a subview to draw a circle on the screen.
This is my view controller class:
gameView is the view linked to in the the storyboard. ballView is the view I would like to add in.
class GameViewController: UIViewController {
@IBOutlet var gameView: UIView!
var ballView = GameBallView()
override func viewDidLoad() {
super.viewDidLoad()
gameView.addSubview(ballView)
ballView.setNeedsDisplay()
gameView.setNeedsDisplay()
}
}
class GameBallView: UIView {
override func drawRect(rect: CGRect) {
let rectForBall = CGRect(x: 50, y: 250, width: 20, height: 20)
let path = UIBezierPath(ovalInRect: rectForBall)
path.fill()
path.stroke()
}
}
drawRect is called, but for some reason nothing shows up on the screen. Does anyone know what I did wrong?