Friday, April 24, 2026
HomeiOS Developmentios - Second ViewController in Xcode challenge isn't the identical width as...

ios – Second ViewController in Xcode challenge isn’t the identical width as my foremost ViewController?

[ad_1]

I’ve created a brand new challenge in Xcode for iOS. I then created a second ViewController in my challenge, identify “TriviaViewController”. Nonetheless, I am noticing that the width of my new view controller isn’t the identical because the width of the principle view controller that was created by Xcode by default.

The width for the principle view controller (ViewController.swift) prints as 414.0
The width of the brand new view controller (TriviaViewController) I’ve created prints as 375.0

So once I add a UILabel to the view, and middle it, the UILabel doesn’t middle.

enter image description here

The code appears fairly straight-forward:

let gameTitle : UILabel = {
    let label = UILabel(body: CGRect(x: 0, y: 150, width: 300, top: 40))
    label.contentMode = UIView.ContentMode.scaleAspectFit
    label.middle.x = self.view.middle.x
    label.textual content = "Trivia"
    label.textAlignment = NSTextAlignment.middle
    label.textColor = UIColor.black
    label.backgroundColor = UIColor.white
    label.numberOfLines = 1
    label.lineBreakMode = NSLineBreakMode.byWordWrapping
    label.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.daring)
    return label
}()
self.view.addSubview(gameTitle)

If I put this identical code in the principle ViewController, it facilities simply superb.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments