CG_INLINE CGRect
CGRectMake1(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
[[ScreenScale shareScreenScale] getScale];
CGRect rect;
rect.origin.x = x * [ScreenScale shareScreenScale].autoSizeScaleX; rect.origin.y = y * [ScreenScale shareScreenScale].autoSizeScaleY;
rect.size.width = width * [ScreenScale shareScreenScale].autoSizeScaleX; rect.size.height = height * [ScreenScale shareScreenScale].autoSizeScaleY;
return rect;
}
//
//ScreenScale.h
//
#import <Foundation/Foundation.h>
@interface ScreenScale : NSObject
@property float autoSizeScaleX;
@property float autoSizeScaleY;
+(ScreenScale *)shareScreenScale;
-(void)getScale;
@end
//
// ScreenScale.m
//
#import "ScreenScale.h"
static ScreenScale * scale;
@implementation ScreenScale
#define ScreenHeight [[UIScreen mainScreen] bounds].size.height//获取屏幕高度,兼容性测试
#define ScreenWidth [[UIScreen mainScreen] bounds].size.width//获取屏幕宽度,兼容性测试
+(ScreenScale *)shareScreenScale
{
if (scale == nil)
{
scale = [[ScreenScale alloc]init];
}
return scale;
}
-(void)getScale
{
if(ScreenHeight > 480){
self.autoSizeScaleX = ScreenWidth/320;
self.autoSizeScaleY = ScreenHeight/568;
}else{
self.autoSizeScaleX = 1.0;
self.autoSizeScaleY = 1.0;
}
}
@end
转载于:https://my.oschina.net/wupengnash/blog/504203