Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
439 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

standalone view in storyboard

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...