How to Set UI Orientation Without Code in iPhone

Introduction

In this article I will try to teach you how to set the screen orientation of an iPhone. In other words, when we make an application in Portrait mode and test in the device, it's content position changes when we move the device into Landscape mode. To understand that use the following procedure.

Step 1

Open ViewController.Xib and click on the top side of the Property window of Xcode. Select file inspector and Unmark "Use Autolayout".

Viewcontroller.Xib-in-iPhone.jpg

Initially, mark "Use Autolayout":

mark-autolayout-in-iPhone.jpg

Here unmark  "Use Autolayout":

unmark-autolayout-in-iPhone.jpg

Step 2

Now click on the Size inspector at the top side of the Property window:

sizeinspector-in-iPhone.jpg

Step 3

Here we set Position (Autosizeing) of all outlets one by one.

First  I select Username Label and set it's size according to Coordinate (x, y). Here I fix it's right side:

set-label-postion-in-iPhone.jpg

Now I select the Text field of the username and fix it's middle portion:

set-textfield-postion-in-iPhone.jpg

Now select the Login button and fix it's frame and bounds according to coordinates:

set-button-postion-in-iPhone.jpg

Step 4

Check the output in the Simulator .

Output

Output 1 (Portrait mode) in iPhone:

output1-in-iPhone.jpg

Output 2 (Landscape Mode) before the set Orientation in the iPhone:

output3-in-iPhone.jpg

Output 3 (Landscape Mode) after the set Orientation in the iPhone:

output2-in-iPhone.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all