I am creating an iPad app which is a form with mostly text boxes. When the iPad is portrait, it displays the text fields vertically in two columns. When I turn the iPad landscape, it still displays the text fields the same exact way except there is open space to the right of the screen. My question is- When the text box is turned landscape, how do you increase the size of the labels and text fields to fill in the open space?
Asked
Active
Viewed 4,719 times
2 Answers
2
Make sure your struts & springs of the textfield are correctly set! Here is what you should set in Interface Builder:
And if you doing this with code here is the code:
myTextField.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin
either way you have to set this to every textfield in you form.

Pfitz
- 7,336
- 4
- 38
- 51
-
Thanks, helped me. I never really noticed this autorezizing feature :-) – Marco Sep 13 '12 at 15:03
1
If you are using a XIB use the inspector to make sure you have the layout guides set to fixed so the width of the text field are at a constant length from the XIB edge - thereby stretching the text field when the interface orientation changes.
If you are laying out your view in code implement the following in your UIViewController subclass:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if( UIInterfaceOrientationIsPortrait(toInterfaceOrientation) ){
// Adjust your text field...
} else if( UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ){
// Adjust your text field...
}
}

Niels Castle
- 8,039
- 35
- 56
-
Also, do you know how to allow a label and a text field to float (move to a different position) when turned to landscape? – Nick Jun 15 '12 at 13:49
-
You are always free to set a new origin coordinate for your labels and text fields manually. If at all possible use the Autosizing masks as described in answer http://stackoverflow.com/questions/5169517 – Niels Castle Jun 16 '12 at 08:53