[英]How to connect custom UIView in interface builder using storyboards?
I want to use an F3BarGauge
( http://www.cocoacontrols.com/controls/f3bargauge ) in my iOS app and I want to use a .storyboard for my UI design. 我想在iOS应用中使用
F3BarGauge
( http://www.cocoacontrols.com/controls/f3bargauge ),并且要在UI设计中使用.storyboard。
I managed to achieve this programmatically by writing code into the view controller's loadView:
method, which creates the instance of the F3BarGauge
and adds it to the view via [self.view addSubview:myBarGauge];
我设法通过将代码写入视图控制器的
loadView:
方法来以编程方式实现此目的,该方法创建F3BarGauge
的实例,并通过[self.view addSubview:myBarGauge];
将其添加到视图中[self.view addSubview:myBarGauge];
. 。
However, now I can't see the F3BarGauge
at all in the preview in Interface Builder and therefor I also can't adjust the size or position of the F3BarGauge
from there. 但是,现在我在Interface Builder的预览中完全看不到
F3BarGauge
,因此也无法从那里调整F3BarGauge
的大小或位置。 I can only do this in the code. 我只能在代码中做到这一点。 Moreover, I think it is confusing for my colleagues if I create parts of the UI elements automatically through the .storyboard and some in my own code.
此外,我认为如果我通过.storyboard自动创建部分UI元素以及使用自己的代码创建部分UI元素,这会让我感到困惑。
I would like to find a solution for both of these disadvantages. 我想为这两个缺点找到解决方案。 It is not important for me to see the actual custom UI element's content (in this case the
F3BarGauge
) in Interface Builder. 对我而言,在Interface Builder中查看实际的自定义UI元素的内容(在本例中为
F3BarGauge
)并不重要。 If the frame of the F3BarGauge
's area is displayed in Interface Builder and I can move and resize it, then I'm happy with the solution. 如果
F3BarGauge
区域的框架显示在Interface Builder中,并且我可以移动它并调整其大小,那么我对该解决方案感到满意。
I do not have an example for this approach, because the example from the author of the F3BarGauge
uses a .xib file and not a .storyboard. 我没有这种方法的示例,因为
F3BarGauge
作者的F3BarGauge
使用F3BarGauge
文件而不是.storyboard。
I'm relatively new to iOS programming and Xcode / Interface Builder. 我是iOS编程和Xcode / Interface Builder的新手。 Maybe there is a better way to achieve what I want than how I imagine my solution.
也许有比我想象的解决方案更好的方法来实现我想要的。
I don't think there is a way to see the F3BarGauge in IB, but you can add a UIView as a subview of your main view in IB, size and position it as you like, and then in code, add the F3BarGauge to the subview. 我认为没有办法在IB中看到F3BarGauge,但是您可以在UI中添加UIView作为主视图的子视图,并根据需要调整其大小和位置,然后在代码中将F3BarGauge添加到子视图。
After Edit: Actually, after looking at the author's demo project, you can see it in IB. 编辑后:实际上,在查看作者的演示项目后,您可以在IB中看到它。 Just copy and paste his view from the demo project into a view controller (after deleting the default view first).
只需将他的视图从演示项目复制并粘贴到视图控制器中(首先删除默认视图之后)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.