Screen adaptation in the use of masonry, or other feeling a little use, screen size adaptation is where I snow in the predecessor, simple to share my writing, immature place to look at more advice, only for reference: recommended to follow the code to knock over, after their users familiar with the convenience, the principle is very simple; there's a lot of crap.
Create Project-Create PCH file: To create a. pch, select the PCH file in other and modify the settings. Set the Precompile Prefix header value to Yes in build settings and set the path to the Prefix header.
Create an extension file uiview+creafream.h, (how to create an extension file: Create a objective-c file, you can select category, extension, protocol, empty files. You can create categories by selecting the category. No longer look at the URL http://blog.csdn.net/idoshi201109/article/details/51735461
I almost forgot what's inside the PCH.
. pch
#ifndef prefixheader_pch#define prefixheader_pch//determine iOS version # define IOS7 ([[Uidevice currentdevice].systemversion Doublevalue] >= 7.0) #import "uiview+creafream.h" #define IPHONE4 ScreenRect.size.width ==320 && ScreenRect.size.height ==480#define IPHONE5 ScreenRect.size.width ==320 && ScreenRect.size.height ==568# Define IPHONE6 ScreenRect.size.width ==375 && ScreenRect.size.height ==667#define iphone6p ScreenRect.size.width ==414 && ScreenRect.size.height ==736//#define IPhone7 iphone7p himself, but with the same size as 6 # define Mas_shorthand#define MAS_SHORTHAND_GLOBALS#ENDIF/* prefixheader_pch */
. h
#import <UIKit/UIKit.h> @interface UIView (creafream)//Only one way to set the interval size + (cgrect) Getrectwithx: (cgfloat) x Y: ( cgfloat) y Width: (cgfloat) W heigth: (cgfloat) H; @end
. m
#import "Uiview+creafream.h" @implementation UIView (Creafream)//Implementation method + (CGRect) Getrectwithx: (cgfloat) x y: (cgfloat) y Width: (cgfloat) W heigth: (cgfloat) h{ cgrect temptect = Cgrectzero; Individuals prefer to compare the size of the iphone as a benchmark if (IPHONE6) { temptect = CGRectMake (x, Y, W, H); } else if ((IPHONE4) | | | (IPHONE5)) { CGFloat xscole = 320/375.0; CGFloat yscole = 480/667.0; Temptect = CGRectMake (X*xscole, Y*yscole, W*xscole, yscole*h); } else if (iphone6p) { cgfloat xscole = 414/375.0; CGFloat yscole = 736/667.0; Temptect = CGRectMake (X*xscole, Y*yscole, W*xscole, yscole*h); } return temptect;} @end
That's it, in use, that's exactly what it is.
When creating a UIView-based attempt to control, frame is not set, such as when creating a Uiimageview: The frame is called with UIView, it can adapt to the other screen Uiimageview * Imgview = [[ Uiimageview alloc] Initwithframe:[uiview getrectwithx:30 y:30 width:100 heigth:100]];
iOS screen fit (size fit)