Search code examples
iosautolayoutinterface-builderiboutlet

How to Auto Resize , UIView Outlet in UIViewController in Interface Builder


I have .xib with UIView size set to w Any and h Any. The problem is it does not resize properly. I am also using auto layout with the .xib. At present there is only one view (which is the view outlet for the UIViewController).

I am looking for the view to resize for screens with multiple resolution ex: 640 * 480, 720 * 480 , 1024 * 768, etc.

So, if do the following, the resize dose not work.

Controller *myController=[[Controller alloc]  initWithNibName:@"Controller" bundle:nil];
[myBaseView addSubview:myController.view];

I also tried to set the "Content Compression Resistance Priority" to 1, which will allow it to resize with less resistance.

enter image description here

But, the following works

UIView *aTestView=[[UIView alloc] initWithFrame:myBaseView.bounds]];
 [myBaseView addSubview: aTestView];

Solution

  • You need to set frame of your viewcontroller's view:

    Controller *myController=[[Controller alloc]  initWithNibName:@"Controller" bundle:nil];
    [myController.view setFrame:superViewFrame];
    [myBaseView addSubview:myController.view];