IPhone 5 adaptation for iOS development

Source: Internet
Author: User

As the popularity of iPhone 5 increases, we have to 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:

 
 
  1. [cpp]  
  2.  
  3. self.view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin    
  4.  
  5. | UIViewAutoresizingFlexibleRightMargin |  UIViewAutoresizingFlexibleBottomMargin     
  6.  
  7. | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;   
  8.  
  9. self.view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin  
  10.  
  11. | UIViewAutoresizingFlexibleRightMargin |  UIViewAutoresizingFlexibleBottomMargin   
  12.  
  13. | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 

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

Code:

 
 
  1. [cpp]  
  2.  
  3. autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;   
  4.  
  5. .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:

 
 
  1. [Cpp]
  2.  
  3. # Define DEVICE_IS_IPHONE5 ([[UIScreen mainScreen] bounds]. size. height = 568)
  4.  
  5. # Define DEVICE_IS_IPHONE5 ([[UIScreen mainScreen] bounds]. size. height = 568). Then we can change the frame during view initialization:
  6.  
  7. [Cpp]
  8.  
  9. If (DEVICE_IS_IPHONE5 ){
  10.  
  11. [Botton setFrame: CGRectMake (0,450,320,440)];
  12.  
  13. }
  14.  
  15. If (DEVICE_IS_IPHONE5 ){
  16.  
  17. [Botton setFrame: CGRectMake (0,450,320,440)];

Related Article

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.