Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem setting autosizing in interface builder

Tags:

I have two viewControllers, one is a subclass of UIViewController (autoresizes correctly), the other one is a subclass of a subclass of UIViewController.
I did a layout in Interface Builder, I tested my code in the Simulator and everything works as expected. But if I rotate the device my views don't resize.
So I went back to Interface Builder and found out that I cannot change the Resizing property of the "root"-UIView. So I opened another file and the resizing property is fixed there, too. But it is set to resizing in both direction. This is the behavior I want.

How can I change the autoresizing of the top UIView so it does what I want?
There are not so many subviews that it is impossible to start again from scratch, but I don't want to do this.

Interface Builder, Autoresizing Mask

like image 242
Matthias Bauch Avatar asked Oct 22 '10 14:10

Matthias Bauch


People also ask

How do I add constraints in Xib?

Select the items you want to align, and then click the Align tool. Interface Builder presents a popover view containing a number of possible alignments. Select the options for aligning the selected views, and click the Add Constraints button. Interface Builder creates the constraints needed to ensure those alignments.

What is Autoresizingmask in IOS?

An integer bit mask that determines how the receiver resizes itself when its superview's bounds change.

Where is Interface Builder in Xcode?

First, in Xcode, go to the Resources folder from the tree view on the left and select MainMenu. xib . It will open in the main view. This is where you are going to build you UI.


2 Answers

I ran into this before and it was incredibly frustrating. It turns out that when you have Simulated User Interface Elements turned on then you can't change the struts and springs like you want.

Go to Attributes tab (Cmd-1) and make sure that Status Bar, Top Bar, Bottom Bar, and Split View are all set to "Unspecified." Then go back to the Size tab (Cmd-3) and you'll be able to click the lines and changes your Struts and Springs. Then finally you can go back to Cmd-1 and turn those simulated elements back on.

like image 100
Kenny Wyland Avatar answered Oct 19 '22 01:10

Kenny Wyland


I have a simplified answer:

  1. Goto IB
  2. Click on the 'ViewController'
  3. Goto 'Attributes Inspector'
  4. Change 'Size' to 'Freeform' (something other than 'Inferred')

What you have is this:

enter image description here

Change 'size' to 'freeform' & try now!

enter image description here

Now, it works! Go back & change it to 'Inferred' after you have set the Autoresizing masks.

like image 29
Jean Avatar answered Oct 19 '22 01:10

Jean