如何在 Interface Builder 中设置高于 480 像素的视图。
这将使用两个 xib 文件来完成:
主视图.xib是 MainViewController 的视图,高 460 像素。
TallView.xib是一个 600 像素高的视图(请参阅下文了解如何在 IB 中执行此操作)。
MainViewController仅包含一个UIScrollView。您的所有内容都应该位于TallView.xib
In 主视图控制器, 覆盖viewDidLoad并使用以下代码:
视图加载:
- (void)viewDidLoad {
//load your TallView.xib into a UIView object
NSArray *nibParts = [[NSBundle mainBundle] loadNibNamed:@"TallView"
owner:nil
options:nil];
//first object is the view
UIView *tallView = [nibParts objectAtIndex:0];
//add tallView to scrollView
[scrollView addSubview:tallView];
//set content size to same dimensions as TallView.xib
scrollView.contentSize = CGSizeMake(320, 600);
}
如何在 Interface Builder 中创建高于 480 像素的视图
通过首先将模拟界面元素设置为来覆盖 xib 的高度超过 480"none",然后更改高度。
看两个屏幕截图:替代文本 http://static.benford.name/IBViewAttributes.png http://static.benford.name/IBViewAttributes.png
替代文本 http://static.benford.name/IBViewSize.png http://static.benford.name/IBViewSize.png