在故事板中创建独立视图以便以编程方式使用 [英] Create a standalone view in storyboard to use programatically

查看:112
本文介绍了在故事板中创建独立视图以便以编程方式使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用故事板创建和设计 UIView ,但是以编程方式将其包含在 UIActionSheet 中。这基本上是为了避免使用带有像素的CoreGraphics定位函数

I'm trying to create and design a UIView using a storyboard but include it in a UIActionSheet programatically. This is basically to avoid using CoreGraphics positioning functions with pixels

在旧的xcode中我记得可以在没有任何控制器的情况下将UIView拖到笔尖上。

In old xcode I remember that it was possible to drag a UIView onto the nib without any controllers.

该视图显然必须连接到该类,因此它将具有IBOutlet,但不会被添加到 self.view

The view obviously has to be connected to the class, so it would have an IBOutlet, but not being added to the self.view

有一件事让我觉得这应该是可能的,如果你将UIView拖入故事板中的控制器黑条,它会弹出到位:

One thing that makes me feel like this should be possible is that if you drag a UIView into the controller black bar in storyboard it pops into place like so:

但它没有显示在屏幕上。这个功能是什么?我可以以某种方式打开这个视图并设计一下吗?

But its not shown on the screen itself. What is this feature for? Can I somehow open up this view and design it a bit?

推荐答案

只需创建一个新的.xib文件。

Just create a new .xib file.


  1. 右键单击导航器区域中的某个位置,然后选择新建文件...。

  2. 选择用户界面 '从右侧列表中选择'查看'。

  3. 点击下一步,下一步,为新视图命名,然后选择创建。

  4. 新的.xib填充将添加到您的项目中。

  5. 双击新的.xib文件,它将在Interface Builder(而不是Storyboard)中打开。

  6. 根据自己的喜好编辑/设计视图。

  1. Right Click somewhere in the Navigator Area and select 'New File...'.
  2. Select 'User Interface' from the list on the right and Select 'View'.
  3. Click 'Next', 'Next', give your new view a name, and 'Create'.
  4. A new .xib fill will be added to your project.
  5. Double clicking on the new .xib file and it opens in Interface Builder (not Storyboard).
  6. Edit/Design your View to your liking.

然后在获得新视图后(。 xib)在Interface Builder中,创建一个新的UIView子类( ex.MyView ),将新视图(.xib)的类切换到MyView,创建一个MyView实例是一个简单的问题。您的控制器,并将其作为子视图添加到您的其他视图。

Then after you have your new view (.xib) in Interface Builder, it's a simple matter of creating a new subclass of UIView (ex. MyView), switching the class of your new view (.xib) to MyView, creating an instance of MyView in your controller, and adding it as a subview to your other view.

* An d在底部回答关于 小黑条 的问题,它被称为Dock,它只是场景顶级文档的迷你表示。该扩展坞便于快速拖放图标并建立连接。请参阅Apple的故事板说明此处。 Ray Wenderlich有一个易于学习的故事板教程这里

*And to answer your question about that little black bar at the bottom, it's called the 'Dock', and it's just a mini representation of the top-level documents of your scene. The dock is convenient for quickly dragging/dropping icons onto and making connections. See apple's storyboard description here. Ray Wenderlich has an easy to follow tutorial on storyboards here.

这篇关于在故事板中创建独立视图以便以编程方式使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆