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
Asked
Active
Viewed 1,063 times
0
-
create a uiview class and add your footer to it in code, subclass it and use for all your other views. – vishnuvarthan Jan 23 '17 at 12:12
-
1Why don't you use `TabBar`? Simple and better way to use TabBar. – Piyush Jan 23 '17 at 12:40
-
If we use tabbar, all views will have a button in footer – Jan 23 '17 at 13:04
2 Answers
1
Create your reusable view as a XIB
and load it programatically where ever you need it. This answer shows how to handle XIB
s.
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
-
I missed the obj-c tag. Sorry. Beside the syntax, it works the same way. – shallowThought Jan 23 '17 at 12:31
-
-
You can not use storyboard for the first approach. But XIB is like storyboard for views without vieeController. Try it. – shallowThought Jan 24 '17 at 21:04
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