0

Hi I'm new to iOS Development, I'm developing an iOS Application in that I want to use same footer throughout the app. Now I'm creating different uiviews in every controller but this is not optimal way. How can I create single uiview and reuse it in app. I'm using storyboards.In my footer I have four buttons

shallowThought
  • 19,212
  • 9
  • 65
  • 112

2 Answers2

1

Create your reusable view as a XIB and load it programatically where ever you need it. This answer shows how to handle XIBs.

This should work fine for your footer.

For more complex reusable views, which make sense to have their own UIViewConroller:

  • create the viewController in storyboard
  • instantiate it like this:

    let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
    let controller = storyboard.instantiateViewController(withIdentifier: "someViewController")
    
  • add it as child viewController like this:

    func add(childViewController controller: UIViewController, embedViewIn containerView: UIView) {
        controller.willMove(toParentViewController: self)
        addChildViewController(controller)
        containerView.addSubview(controller.view)
        // addCustomConstraints
    }
    

You can later remove the child viewController like this:

func remove(childViewController controller: UIViewController) {
    controller.willMove(toParentViewController: nil)
    controller.view.removeFromSuperview()
    controller.removeFromParentViewController()
}
Community
  • 1
  • 1
shallowThought
  • 19,212
  • 9
  • 65
  • 112
0

You have to use custom tabBar, Have a look at https://github.com/hartlco/MHCustomTabBarController this link, I have implemented it its easy to understand.

Nisar Ahmad
  • 885
  • 1
  • 10
  • 25