如何在iOS Swift中为多个ViewControllers添加公共视图?

Mus*_*ula 1 uiviewcontroller uiview ios swift

我是iOS开发的新手.
我希望在其中包含自定义视图和一些标签.在我的应用程序的一些viewControllers中按一下按钮,我想在viewController的底部添加/显示View.

至于我手动在故事板中添加我想要显示视图的所有viewControllers中的视图.但这并不高效.如何在按钮单击时以编程方式在viewControllers中添加此视图?

san*_*eet 6

使用UIViewController继承一个BaseViewController类

现在在BaseViewController中创建名为designFooter的方法

func designFooter() {
    var viewFooter: UIView = UIView(frame: CGRectMake(0, self.view.bounds.size.height - 50, self.view.bounds.size.width, 50))
    viewFooter.backgroundColor = UIColor.redColor()
    self.view!.addSubview(viewFooter)
}
Run Code Online (Sandbox Code Playgroud)

现在继承这个BaseViewController给你想要添加页脚的ViewController,点击按钮就可以调用self.designFooter()