In a Swift playground, how do I center a UILabel
inside of a UIViewController
?
When I use title.center = CGPoint(x: vc.view.frame.width / 2, y: 20)
the text goes off of the screen.
This is the problem
If it helps, here's my code.
import UIKit
import PlaygroundSupport
// Set up ViewController and other things
var vc = UIViewController()
vc.view.frame.size.height = 75
vc.view.backgroundColor = .white
let title = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 50))
title.textAlignment = .center
title.center = vc.view.center
title.text = "Which code is correct?"
vc.view.addSubview(title)
PlaygroundPage.current.liveView = vc