推送视图控制器时标签未显示

问题描述

当我按下视图控制器时,我的标签没有显示,有人知道为什么以及如何修复它吗?

@IBAction func tapButton (_ sender: Any) {

    let vc = UIViewController()
    Vc.view.backgroundColor = .gray
    
    let label = UILabel()
    
    label.font = UIFont(name: “Arial”,size: 16.0)
    
    label.text = “Test label”
    
    Other label configurations...
    
    vc.view.addSubView(label)
    
    navigationController?.pushViewController(vc,animated: true)

}

解决方法

您应该在标签上添加一些约束(以便将其放置在第二个View Controller上):

Vue