中心在中心对齐子视图UIview

时间:2016-05-29 10:11:41

标签: ios uiview xcode-storyboard ios-autolayout

我有以下基于故事板的设计和约束 enter image description here

enter image description here

enter image description here

我将此视图添加到主视图中,如下所示

 NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"CompanyFundView" owner:nil options:nil];
CompanyFundView *view = [nibContents lastObject];
UIWindow* mainWindow = [[UIApplication sharedApplication] keyWindow];
UIView *parent = mainWindow.subviews[0];

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;

view.frame = CGRectMake(0, 0, screenWidth, screenHeight);
[parent addSubview:view];

正如您所看到的那样,视图未显示在主视图中且未调整大小,我需要添加哪些其他约束?

1 个答案:

答案 0 :(得分:0)

确保在故事板场景中添加NSLayoutConstraint,其宽度和高度设置为w:Any h:Any

我可以看到您正在使用w:Any Regular

约束是特定的,所以它不会缩放。

在处理目标设备尺寸的特定布局时使用特定的场景尺寸