想要xib文件覆盖整个屏幕而不是覆盖左上角ios

问题描述:

我正在制作一个ios应用程序,并使用xib文件而不是故事板。起初,我甚至没有使用自动布局一切工作正常的肖像所有iPhone设备。但只要我通过assests添加启动屏幕,只有iphone 5具有正确的布局(因为xib文件大小设置为4英寸)。但是,任何更大的屏幕尺寸和只有左上角覆盖象下面这样:想要xib文件覆盖整个屏幕而不是覆盖左上角ios

enter image description here

我想以覆盖整个屏幕。顶部有一个视图,但我不能添加任何约束。在视图内部有一个应该覆盖整个屏幕的图像视图。所以我添加了4个约束并将4个边固定为0,因此imageview应该覆盖整个屏幕。但它仍然不起作用。我能做些什么,整个屏幕将被覆盖?

+0

之前_launch screen_屏幕只是由iOS放大,你没有做适当的iPhone6/6s屏幕支持;现在使用_launch屏幕_ iOS不会执行向上采样,您需要正确设置自动布局的界面以将布局应用于多种尺寸的屏幕 - 这就是您的应用看起来处于左上角的原因;它不是xib与storyboard的问题,只能部署约束条件。 – holex

您是否尝试过设置框架?

NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"xibFileName" owner:nil options:nil];   
[[array objectAtIndex:0] setFrame:self.view.frame]; // Trick here: set the main view frame 

这个工作在我的情况:

// Create a Container 
    UIView *container = [[UIView alloc] initWithFrame:self.view.frame]; 
    container.backgroundColor = [UIColor clearColor]; 

// Add .xib file on top of the screen 
    NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"xibFileName" owner:nil options:nil];   
    [container addSubview:[array objectAtIndex:0]]; 

// Add container to main view 
    [self.view addSubview:container]; 

关于你要设置的约束有内部的.xib文件itens。