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?

Answers


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

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.


Need Your Help

SQL reduce the amout of selects on table

oracle11g query-performance

I have a performance problem with my SQL query: (on Oracle SQL)

Android : How to Convert a Java.String into a JSONObject

java php android mysql json

I've just started coding using Android Studio and i stumbled into a problem I cant find a solution for.