简体   繁体   中英

Editing Custom UIView Subclasses in Storyboard

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).

Thanks in advance.

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

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.

ORIGINAL

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

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM