Search code examples
iosobjective-cxcodeautolayoutxib

UIView in XIB using Autolayout is always 600x600


I created a separate .xib because I wanted to design a UIView with autolayout outside of a viewController. I created the .xib, added the UIView and the constraints, using wCompact hRegular. Simple.

enter image description here

Then add it to my viewController in viewDidLoad:

UIView *header = [[[NSBundle mainBundle] loadNibNamed:@"HeaderSearch" owner:self options:nil] lastObject];
NSLog(@"%@", NSStringFromCGRect(header.frame));
[self.view addSubview:header];

But, when it is added, the frame size is 600x600 and I cannot figure out why.

What have I done wrong here that is forcing this strange size?


Solution

  • You need to uncheck 'Use size classes' in your xib

    uncheck size classes

    and the view frame size will be the one you set and not 600x600