简体   繁体   中英

Is it possible to use a single UIView across multiple UIViewControllers?

I have 6 UIViewControllers in my app at the moment, and while they are all different, they should all share the same custom toolbar at the top, as well as a drawer which is opened/closed by a button on said toolbar. The "toolbar" and "drawer" are both UIViews with some stuff inside. Is it possible to use the same UIView objects for all 6 of my UIViewControllers? Or do I have to copy the constraints, segues, controller code, etc for the toolbar and drawer for each UIViewController that I have in my app?

Take a look at containerView .

You can add containerViews in each of your ViewControllers and embed your UIView.

What you could do in this situation is make a view controller that embeds a child view controller. On this view controller, you would set up your toolbar and drawer, then you would have a Container View that can embed a navigation controller which would manage all your other view controllers. On a storyboard, you can right-click and drag from a Container View to another controller to embed it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM