如何通过代码用FreeForm创建UIViewController?不使用故事板

时间:2019-04-08 07:42:29

标签: swift uiviewcontroller

使用Freeform选项创建带有代码的UIViewController时遇到问题。 注意:我不为此UIViewController使用故事板。

1 个答案:

答案 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())
相关问题