Pure Code Fit

Source: Internet
Author: User

Pure Code Fit


First look at the Apple Model screen width-height ratio

4.0 inch (IPhone 5,iphone 5S) ratio of width to height 320/568 = 0.563

4.7 inch (IPhone 6,iphone 6s,iphone 7,iphone 7S) ratio of width to height 375/668 = 0.562

5.5 inch (iPhone 6 plus,iphone 6S plus,iphone 7 plus,iphone 7S Plus) ratio of width to height 414/736 = 0.5625

You can see that the aspect ratio is basically equal, so you can calculate the frame on the other screen based on one screen resolution, as follows:


Get Screen width height

#define ScreenWidth [UIScreen mainscreen].bounds.size.width;

#define ScreenHeight [UIScreen mainscreen].bounds.size.height;

Base on 4.0 inch screen (iphone5s), or 4.7-inch or 5.5-inch screen

#define AUTOSIZESCALEX [UIScreen mainscreen].bounds.size.width/320.0;

#define Autosizescaley [UIScreen mainscreen].bounds.size.height/568.0;

Inline Definition Dimension Method macros

Cg_inline cgrect Msrectmake (cgfloat x, cgfloat y, cgfloat width, cgfloat height)

{

CGRect rect;

rect.origin.x = x * AUTOSIZESCALEX;

RECT.ORIGIN.Y = y * Autosizescaley;

Rect.size.width = width * AUTOSIZESCALEX;

Rect.size.height = height * Autosizescaley;

return rect;

}

Usage: Replace the rectmake of the system with Msrectmake

UIView *myview = [[UIView alloc] Initwithframe:msrectmake (15, 64 + 15, 290, 50)];

Myview.backgroundcolor = [Uicolor blackcolor];

[Self.view Addsubview:myview];


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.