简体   繁体   English

在iOS中重用自定义工具栏

[英]Reusing a Custom Toolbar in iOS

I created this nice custom toolbar that sits on one of my scenes, this scene uses its own viewcontroller. 我创建了这个漂亮的自定义工具栏,它位于我的一个场景中,这个场景使用自己的viewcontroller。 Prior to this I had no need to put it on any other viewcontroller, but after making modifications to my application I now need to put this toolbar on another viewcontroller/scene. 在此之前,我没有必要将它放在任何其他视图控制器上,但在对我的应用程序进行修改后,我现在需要将此工具栏放在另一个viewcontroller / scene上。 I would prefer not to have to re-create the whole UI aspect of it again and connect up everything. 我宁愿不再重新创建它的整个UI方面并连接所有内容。

Ive created this toolbar on a scene using a storyboard. 我已经使用故事板在场景上创建了这个工具栏。 Is it possible somehow to reuse all the elements I've created for this toolbar (the code for all the logic already sits in its own class)? 有可能以某种方式重用我为此工具栏创建的所有元素(所有逻辑的代码已经存在于自己的类中)? Or would I need to create the entire toolbar in the code for this to be possible? 或者我是否需要在代码中创建整个工具栏才能实现此目的? Is there any easier way that I just dont know about? 有没有更简单的方法,我只是不知道?

I think you have two options here. 我想你在这里有两个选择。 One would be to keep the custom toolbar view always on the screen, and change the views around it to whatever you like. 一种方法是将自定义工具栏视图始终保留在屏幕上,并将其周围的视图更改为您喜欢的任何内容。 Another option would be to create an instance of your toolbar from any class you need, then add it's view as a subview everytime you need it. 另一种选择是从您需要的任何类创建工具栏的实例,然后在每次需要时将其视图作为子视图添加。

Either way, I think you may need to rework some the toolbar to not sit on a scene, but have it's own. 无论哪种方式,我认为你可能需要重新设计一些工具栏,而不是坐在场景上,而是拥有它自己。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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