在Storyboard中编辑自定义UIView子类 [英] Editing Custom UIView Subclasses in Storyboard

查看:511
本文介绍了在Storyboard中编辑自定义UIView子类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它使用UIScrollView在多个动态生成的UIView之间进行分页。现在,我必须以编程方式设置这些UIViews的布局和ui元素,但我想知道是否有任何方法可以在storyboard中编辑UIView子类的接口(独立于视图控制器)。

I have an application that uses a UIScrollView to page between a number of dynamically generated UIViews. Right now, I have to programmatically set the layout and ui elements of these UIViews, but I was wondering if there is any way to edit the interface of a subclass of UIView in storyboard (independent of a view controller).

提前致谢。

编辑:仅供参考,我在iOS 5上使用Xcode 4.2。

Just for reference, I'm using Xcode 4.2 with iOS 5.

推荐答案

UPDATE



从Xcode 7开始,您可以在故事板中编辑独立视图。将视图从对象库拖动到视图控制器的标题栏。 Interface Builder将在视图控制器主视图上方的画布上单独显示独立视图。示例:

UPDATE

As of Xcode 7, you can edit a standalone view in a storyboard. Drag a view from the Object Library to the header bar of a view controller. Interface Builder will show the standalone view separately on the canvas above the view controller's main view. Example:

您可能希望创建一个从视图控制器出口到独立视图。只能从包含它的视图控制器访问独立视图。

You will probably want to create an outlet from your view controller to the standalone view. The standalone view will only be accessible from the view controller that contains it.

请注意,在加载视图控制器时,您将获得一个独立视图实例。如果你需要多个实例,没有特别好的方法可以获得它们。

Note that you get one instance of the standalone view when you load the view controller. If you need multiple instances, there's no particularly good way to get them.

没有方便在故事板中执行此操作的方法。

There is no convenient way to do this in a storyboard.

您仍然可以在使用故事板的项目中创建nib。因此,您可以为每个视图创建一个nib,并从代码中加载它们:

You can still create nibs in a project that uses a storyboard. So you can create a nib for each view, and load them from your code:

NSString *nibName = [NSString stringWithFormat:@"page%d", pageNumber];
NSArray *nibObjects = [NSBundle.mainBundle loadNibNamed:nibName owner:self options:nil];
UIView *pageView = [nibObjects objectAtIndex:0];
CGSize size = self.scrollView.bounds.size;
pageView.frame = CGRectMake(pageNumber * size.width, 0, size.width, size.height);
[self.scrollView addSubview:pageView];

这篇关于在Storyboard中编辑自定义UIView子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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