I've created a new project in Xcode for iOS. I then created a second ViewController in my project, name "TriviaViewController". However, I'm noticing that the width of my new view controller is not the same as the width of the main view controller that was created by Xcode by default.
The width for the main view controller (ViewController.swift) prints as 414.0 The width of the new view controller (TriviaViewController) I've created prints as 375.0
So when I add a UILabel to the view, and center it, the UILabel does not center.
The code seems pretty straight-forward:
let gameTitle : UILabel = {
let label = UILabel(frame: CGRect(x: 0, y: 150, width: 300, height: 40))
label.contentMode = UIView.ContentMode.scaleAspectFit
label.center.x = self.view.center.x
label.text = "Trivia"
label.textAlignment = NSTextAlignment.center
label.textColor = UIColor.black
label.backgroundColor = UIColor.white
label.numberOfLines = 1
label.lineBreakMode = NSLineBreakMode.byWordWrapping
label.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.bold)
return label
}()
self.view.addSubview(gameTitle)
If I put this same code in the main ViewController, it centers just fine.