問題描述
我想設(shè)計(jì)一個(gè) UIView,它比 Storyboard (iOS 5) 中的 ViewController 大.
I would like to design a UIView, which is larger than a ViewController in Storyboard (iOS 5).
UIView 應(yīng)該用作 UIScrollView 的子視圖,因此比我現(xiàn)有的任何 ViewController 都大.如何在 Storyboard 中創(chuàng)建這樣的 UIView 并將其與我的 UIScrollView 關(guān)聯(lián)?
The UIView should be used as the subview of a UIScrollView and hence be larger than any of my existing ViewControllers. How can I create such a UIView in Storyboard and associate it with my UIScrollView?
如果可能,我希望不使用 xib 文件.
I would like to do this without xib files if possible.
謝謝!
推薦答案
除了使用 xibs,我沒有其他選擇,但它并不那么煩人:
I see no other option than using xibs, but it's not that annoying:
//We have file called "View.xib" in our project. It contains one SINGLE view
NSArray *xibContents = [[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:nil];
UIView *view = [xibContents lastObject]; //safer than objectAtIndex:0
[self.scrollview addSubview:view];
self.scrollview.contentSize = view.frame.size;
為了建立 IB 連接,您可以將 xib 中的 filesOwner
類設(shè)置為您的 viewController,然后像往常一樣連接.
In order to make IB connections you can set the filesOwner
class in the xib to be your viewController, and connect like usual.
這篇關(guān)于如何在 Storyboard 中的任何 ViewController 之外設(shè)計(jì)單獨(dú)的 UIView?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!