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];