在情节提要中创建独立视图以编程方式使用 [英] Create a standalone view in storyboard to use programmatically

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

问题描述

我正在尝试使用情节提要板创建和设计UIView,但以编程方式将其包含在UIActionSheet中.基本上是为了避免将CoreGraphics定位功能与像素一起使用

I'm trying to create and design a UIView using a storyboard but include it in a UIActionSheet programmatically. 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. 根据自己的喜好编辑/设计视图.

然后在Interface Builder中拥有新视图(.xib)之后,只需创建一个新的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.

*并在底部回答有关该 小黑条 的问题,它称为"Dock",它只是顶层的一个微型表示形式您场景的文档.扩展坞可方便地将图标快速拖放到并建立连接.请在此处中查看苹果的故事板描述. 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天全站免登陆