使用Freeform选项创建带有代码的UIViewController时遇到问题。 注意:我不为此UIViewController使用故事板。
答案 0 :(得分:0)
通常,在viewController中创建UIView
let view2 = UIView()
view2.backgroundColor = .red
self.view.addSubview(view2)
view2.topAnchor.constraint(view.topAnchor, constant: 100).isActive = true
view2.leftAnchor.constraint(view.leftAnchor, constant: 100).isActive = true
view2.bottomAnchor.constraint(view.bottomAnchor, constant: 100).isActive = true
view2.rightAnchor.constraint(view.rightAnchor, constant: 100).isActive = true
如果您要创建viewController
并推送到它,则需要创建一个带有UIViewController
子类的新文件,然后使用此代码进行导航
self.navigationViewController?.pushViewController(rootViewController: NewFileViewController())