Pure Code Development Screen adaptation processing method:
For models that fit the iphone versions, initialize the coordinates in the UI layout in a proportional manner, where iphone6 is selected as the UI layout
1. First define two properties in AppDelegate.h:
1 #import <UIKit/UIKit.h> 2 3@interface Appdelegate:uiresponder < Uiapplicationdelegate> 4 5 @property (Strong, Nonatomic) UIWindow *window; 6 7 8 @property (nonatomic,assign) cgfloat Autosizescalex; 9 @property (nonatomic,assign) cgfloat Autosizescaley; Ten One @end
2. Initialize the property in APPDELEGATE.M (calculates the ratio of the screen size of the currently running iphone version to the Iphone6 selected when designing the UI):
#import "AppDelegate.h"@interfaceappdelegate ()@end@implementationappdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {//Override point for customization after application launch.Self.autosizescalex= [UIScreen mainscreen].bounds.size.width/375; Self.autosizescaley= [UIScreen mainscreen].bounds.size.height/667; returnYES;}@end
3. In the place where UI layout is required, the data is initialized with inline functions (the inline function is executed when the program is compiled, the benefit of which is to speed up the program at run time, without having to compute the coordinates at run time):
#import "ViewController.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Self.view.backgroundColor=[Uicolor Whitecolor]; UIButton*BTN =[UIButton Buttonwithtype:uibuttontypecustom]; [BTN Settitle:@"Login"Forstate:uicontrolstatenormal]; [btn Settitlecolor:[uicolor Redcolor] forstate:uicontrolstatenormal]; Btn.frame= CGRectMake1 ( -, -,335, -); Btn.backgroundcolor=[Uicolor Greencolor]; [Self.view addsubview:btn];}//Create an inline function (executed when the program compiles, after the function is declared, the compiler executes more efficiently, making the definition of the macro more economical and does not involve the operation of the stack)cg_inline CGRectCGRectMake1 (cgfloat x,cgfloat y,cgfloat width,cgfloat height) {//create Appdelegate object in which the class is not generated (there is no problem causing circular references)Appdelegate *app = [UIApplication sharedapplication].Delegate; //calculates the return returnCGRectMake (x * app.autosizescalex, Y * app.autosizescaley, Width * app.autosizescalex, Height *App.autosizescaley);}- (void) didreceivememorywarning {[Super didreceivememorywarning];}@end
4. Advanced: Put the inline function into a viewcontroller, and then use this viewcontroller as the parent of the other Viewcontroller, so you can write only one inline function, It then calls and uses it multiple times in other viewcontroller, saving the amount of code.
Object C Pure Code Development screen adaptation processing method in iOS