在 Storyboard 中编辑自定义 UIView 子类

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

问题描述

我有一个应用程序,它使用 UIScrollView 在多个动态生成的 UIView 之间进行分页.现在,我必须以编程方式设置这些 UIView 的布局和 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.

推荐答案

更新

从 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 子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

AWS DynamoDB Batch Get Request - iOS(AWS DynamoDB 批量获取请求 - iOS)
Querying DynamoDB on non-key attributes(在非关键属性上查询 DynamoDB)
DynamoDB auto incremented ID amp; server time (iOS SDK)(DynamoDB 自动递增 ID amp;服务器时间(iOS SDK))
Where to find a clear explanation about swift alert (UIAlertController)?(哪里可以找到关于 swift alert (UIAlertController) 的清晰解释?)
Swift alert view with OK and Cancel: which button tapped?(带有 OK 和 Cancel 的 Swift 警报视图:点击了哪个按钮?)
Facebook Requests Dialog: Frictionless Requests in native iOS app possible?(Facebook 请求对话框:本机 iOS 应用程序中的无摩擦请求可能吗?)