Nick
Nick

Reputation: 71

How to change the size of text fields when turned to landscape Xcode

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?

Upvotes: 0

Views: 4768

Answers (2)

Pfitz
Pfitz

Reputation: 7344

Make sure your struts & springs of the textfield are correctly set! Here is what you should set in Interface Builder:

enter image description here

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.

Upvotes: 2

Niels Castle
Niels Castle

Reputation: 8069

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...
    }
}

Upvotes: 1

Related Questions