Screen adaptation methods in various screen sizes

Source: Internet
Author: User

  

Since the advent of the iPhone 6 and iPhone 6 plus, the iPhone needs to adapt to four screen sizes, and screen adaptation has become the most important question for developers.

  

IPhone 4, iPhone 4S, resolution 960*640, Aspect Ratio 1.5

IPhone 5, iPhone 5S, resolution 1136*640, Aspect Ratio 1.775

IPhone 6, resolution 1334*750, Aspect Ratio 1.778

IPhone 6 +, resolution 1920*1080, Aspect Ratio 1.777It can be seen that only the aspect ratios of iPhone 4 and iPhone 4S are different from those of iPhone 5 and above. You can roughly think that the aspect ratios of iPhone 5, 5 s, 6, and 6 + are the same and can be scaled proportionally, although there are subtle differences, it is basically impossible to see.

Based on this, we found three adaptation solutions.

1. Use the old version of xcode to edit the project

I believe many people have discovered that after the appearance of iPhone 6 and iPhone 6 plus, previously, only 320*480 and 320*568 apps can run on 6 and 6 plus slightly perfectly, except that image resources are enlarged in the same proportion.

Then I compare the settings of the old and new projects one by one, hoping to find out the differences, but I didn't find them. So if I use this method, I can only use the project edited by the old version of xcode, delete unnecessary code and use it.

 

2. Use a custom cgsizemake () method  

// Screen width and height

# Define screen_width [[uiscreen mainscreen] bounds]. Size. Width

# Define screen_height [[uiscreen mainscreen] bounds]. Size. Height

 

# Define auto_size_scale_x screen_width/320366f

# Define auto_size_scale_y screen_height/568.0f

 

 

// Use the new coordinate method to solve the adaptation problem of four sizes

Cg_inline cgrect

Cgrectmakenew (cgfloat X, cgfloat y, cgfloat width, cgfloat height)

{

Float autosizescalex = 1.0f;

Float autosizescaley = 1.0f;

If (screen_height & gt; 480 ){

Autosizescalex = auto_size_scale_x;

Autosizescaley = auto_size_scale_y;

}

Cgrect rect;

Rect. Origin. x = x * autosizescalex;

Rect. Origin. Y = y * autosizescaley;

Rect. Size. width = width * autosizescalex;

Rect. Size. Height = height * autosizescaley;

Return rect;

}

 

Iii. Use Automatic Layout

Automatic Layout is the perfect solution, but it requires various constraints to be added for automatic layout, which is troublesome to use. The autolayout document is attached.

Http://www.cocoachina.com/ios/20141217/10669.html

Screen adaptation methods in various screen sizes

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.