Iphone development adaptation to iphone 5

Source: Internet
Author: User

When the iPhone 5 comes out, we will adapt to screens with different resolutions like android.

The new version of the company's products must be adapted to the iPhone 5. After some effort, it is done. I would like to share with you the following:

IPhone 5 screen resolution: 1136x640, that is, when the height changes to 568, the name of the image is default-568h@2x.png. When we create a project, xcode creates a pure black image by default.

The latest version of xcode supports debugging for iPhone 5: select the simulator ----> device ----> iPhone (retina 4-inch). You can switch to the iPhone 5 simulator in a moment.

To adapt to iPhone 5, you must set the autosizing of the view to the following status:


Of course, make sure to select another item.


This option is selected by default, which means the subview is automatically scaled.

If our view does not use XIB, we can use the code to set these attributes:

self.view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin |  UIViewAutoresizingFlexibleBottomMargin  | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

Next, set the sub-view (such as button and image ):


Code:

.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;

This means that when the control is scaled, it corresponds to the left and top of the parent view. You can set the autorizingmask value for the Child control as needed.

You can also use the code to manually change the size or location of the control in iPhone 5:
First determine whether the device is iphone5:

#define DEVICE_IS_IPHONE5 ([[UIScreen mainScreen] bounds].size.height == 568) 

Then, we can change the frame when the view is initialized:

if (DEVICE_IS_IPHONE5) {        [botton setFrame:CGRectMake(0, 450, 320, 440)];}

Through the above work, we can perfectly adapt to the iPhone 5.
Haha, That's easy!
Please leave a message if you have any questions!
Note: Please indicate the source for reprinting!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.