简体   繁体   English

如何使用故事板在界面构建器中连接自定义UIView?

[英]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应用中使用F3BarGaugehttp://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.

相关问题 在Interface Builder上,将UILabel连接到自定义UIView IBOutlet - On Interface Builder connect UILabel to custom UIView IBOutlet Interface Builder - 如何创建具有许多子视图的自定义UIView - Interface Builder - How to create a custom UIView with many subviews 将自定义UIView渲染到情节提要 - Render Custom UIView to Storyboards Interface Builder正在将自定义视图分配为常规UIView - Interface Builder is allocating a custom view as a regular UIView 如何使用Interface Builder创建的nib文件加载UIView - How to load a UIView using a nib file created with Interface Builder 如何使用情节提要在界面构建器中编辑手动添加的UINavigationBar子视图? - How can I edit a manually added UINavigationBar sub view in interface builder using storyboards? 使用Interface Builder和故事板构建控制器之间的关系 - Using Interface Builder and storyboards to build relationships between controllers 如何在Interface Builder中正确使UIView工作 - How to properly make a UIView work in Interface Builder 如何在方向更改时在界面构建器的uiview中拉伸uiview? - how to stretch a uiview within a uiview in interface builder on orientation change? 如何仅使用界面生成器将UIButton连接到动作 - How to connect UIButton to action using only interface builder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM